summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2023-12-10 09:12:16 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2023-12-10 09:12:16 +0100
commit98d5b5a2728e640f9d553648812df379c5534395 (patch)
tree43925bf57048fdbebe076125894a50f5877b99be
parenta9dd549dc85faf17ce211ff0ab5be4c9863440ed (diff)
parent81eadf8cdfcfa964401b5cf5d1e80cc21ec4441f (diff)
feat: display the total count of entries-to-be-deleted in the mark pane.
This allows to better estimate how much work will be needed to perform the deletion. For example, when marking 3 items for deletion, previously one would see `3 items marked`, but now one will see all items and sub-items, like `120k`items marked`, which reflects the work that will be done much more precisely.
-rw-r--r--src/interactive/widgets/entries.rs9
-rw-r--r--src/interactive/widgets/mark.rs17
-rw-r--r--src/interactive/widgets/mod.rs7
3 files changed, 20 insertions, 13 deletions
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs
index 9357587..e50a0a1 100644
--- a/src/interactive/widgets/entries.rs
+++ b/src/interactive/widgets/entries.rs
@@ -1,3 +1,4 @@
+use crate::interactive::widgets::COUNT;
use crate::interactive::{
path_of,
widgets::{entry_color, EntryMarkMap},
@@ -5,9 +6,7 @@ use crate::interactive::{
};
use chrono::DateTime;
use dua::traverse::{EntryData, Tree, TreeIndex};
-use human_format;
use itertools::Itertools;
-use once_cell::sync::Lazy;
use std::time::SystemTime;
use std::{borrow::Borrow, path::Path};
use tui::{
@@ -24,12 +23,6 @@ use tui_react::{
List, ListProps,
};
-static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
- let mut formatter = human_format::Formatter::new();
- formatter.with_decimals(0).with_separator("");
- formatter
-});
-
pub struct EntriesProps<'a> {
pub tree: &'a Tree,
pub root: TreeIndex,
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs
index ff534da..ffb5143 100644
--- a/src/interactive/widgets/mark.rs
+++ b/src/interactive/widgets/mark.rs
@@ -1,3 +1,4 @@
+use crate::interactive::widgets::COUNT;
use crate::interactive::{
fit_string_graphemes_with_ellipsis, path_of, widgets::entry_color, CursorDirection,
};
@@ -41,6 +42,7 @@ pub struct EntryMark {
pub index: usize,
pub num_errors_during_deletion: usize,
pub is_dir: bool,
+ pub entry_count: Option<u64>,
}
#[derive(Default)]
@@ -51,6 +53,7 @@ pub struct MarkPane {
has_focus: bool,
last_sorting_index: usize,
total_size: u128,
+ item_count: u64,
}
pub struct MarkPaneProps {
@@ -89,6 +92,7 @@ impl MarkPane {
index: sorting_index,
num_errors_during_deletion: 0,
is_dir,
+ entry_count: e.entry_count,
});
}
}
@@ -101,7 +105,7 @@ impl MarkPane {
if self.marked.is_empty() {
None
} else {
- self.total_size = calculate_size(&self.marked);
+ (self.total_size, self.item_count) = calculate_size_and_count(&self.marked);
Some(self)
}
}
@@ -242,7 +246,7 @@ impl MarkPane {
let marked: &_ = &self.marked;
let title = format!(
"Marked {} items ({}) ",
- marked.len(),
+ COUNT.format(self.item_count as f64),
format.display(self.total_size)
);
let selected = self.selected;
@@ -430,7 +434,7 @@ impl MarkPane {
}
}
-pub fn calculate_size(marked: &EntryMarkMap) -> u128 {
+pub fn calculate_size_and_count(marked: &EntryMarkMap) -> (u128, u64) {
let entries: Vec<&EntryMark> = marked
.iter()
.map(|(_k, v)| v)
@@ -438,6 +442,7 @@ pub fn calculate_size(marked: &EntryMarkMap) -> u128 {
.collect();
let mut size = 0u128;
+ let mut item_count = 0u64;
for (idx, entry) in entries.iter().enumerate() {
let mut is_subdirectory = false;
for other in &entries[0..idx] {
@@ -448,9 +453,10 @@ pub fn calculate_size(marked: &EntryMarkMap) -> u128 {
}
if !is_subdirectory {
size += entry.size;
+ item_count += entry.entry_count.unwrap_or(1);
}
}
- size
+ (size, item_count)
}
#[cfg(test)]
@@ -475,6 +481,7 @@ mod mark_pane_tests {
size: 10,
path: PathBuf::from("root"),
is_dir: true,
+ entry_count: Some(2),
..Default::default()
},
);
@@ -495,6 +502,6 @@ mod mark_pane_tests {
},
);
- assert_eq!(calculate_size(&marked), 15u128);
+ assert_eq!(calculate_size_and_count(&marked), (15u128, 3u64));
}
}
diff --git a/src/interactive/widgets/mod.rs b/src/interactive/widgets/mod.rs
index 2c11ff1..29d32aa 100644
--- a/src/interactive/widgets/mod.rs
+++ b/src/interactive/widgets/mod.rs
@@ -11,12 +11,19 @@ pub use header::*;
pub use help::*;
pub use main::*;
pub use mark::*;
+use once_cell::sync::Lazy;
use tui::style::Color;
pub const COLOR_MARKED: Color = Color::Yellow;
pub const COLOR_MARKED_DARK: Color = Color::Rgb(176, 126, 0);
+static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
+ let mut formatter = human_format::Formatter::new();
+ formatter.with_decimals(0).with_separator("");
+ formatter
+});
+
fn entry_color(fg: Option<Color>, is_file: bool, is_marked: bool) -> Option<Color> {
match (is_file, is_marked) {
(true, false) => fg,