Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98d5b5a

Browse files
committed
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.
2 parents a9dd549 + 81eadf8 commit 98d5b5a

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/interactive/widgets/entries.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
use crate::interactive::widgets::COUNT;
12
use crate::interactive::{
23
path_of,
34
widgets::{entry_color, EntryMarkMap},
45
DisplayOptions, EntryDataBundle, SortMode,
56
};
67
use chrono::DateTime;
78
use dua::traverse::{EntryData, Tree, TreeIndex};
8-
use human_format;
99
use itertools::Itertools;
10-
use once_cell::sync::Lazy;
1110
use std::time::SystemTime;
1211
use std::{borrow::Borrow, path::Path};
1312
use tui::{
@@ -24,12 +23,6 @@ use tui_react::{
2423
List, ListProps,
2524
};
2625

27-
static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
28-
let mut formatter = human_format::Formatter::new();
29-
formatter.with_decimals(0).with_separator("");
30-
formatter
31-
});
32-
3326
pub struct EntriesProps<'a> {
3427
pub tree: &'a Tree,
3528
pub root: TreeIndex,

src/interactive/widgets/mark.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::interactive::widgets::COUNT;
12
use crate::interactive::{
23
fit_string_graphemes_with_ellipsis, path_of, widgets::entry_color, CursorDirection,
34
};
@@ -41,6 +42,7 @@ pub struct EntryMark {
4142
pub index: usize,
4243
pub num_errors_during_deletion: usize,
4344
pub is_dir: bool,
45+
pub entry_count: Option<u64>,
4446
}
4547

4648
#[derive(Default)]
@@ -51,6 +53,7 @@ pub struct MarkPane {
5153
has_focus: bool,
5254
last_sorting_index: usize,
5355
total_size: u128,
56+
item_count: u64,
5457
}
5558

5659
pub struct MarkPaneProps {
@@ -89,6 +92,7 @@ impl MarkPane {
8992
index: sorting_index,
9093
num_errors_during_deletion: 0,
9194
is_dir,
95+
entry_count: e.entry_count,
9296
});
9397
}
9498
}
@@ -101,7 +105,7 @@ impl MarkPane {
101105
if self.marked.is_empty() {
102106
None
103107
} else {
104-
self.total_size = calculate_size(&self.marked);
108+
(self.total_size, self.item_count) = calculate_size_and_count(&self.marked);
105109
Some(self)
106110
}
107111
}
@@ -242,7 +246,7 @@ impl MarkPane {
242246
let marked: &_ = &self.marked;
243247
let title = format!(
244248
"Marked {} items ({}) ",
245-
marked.len(),
249+
COUNT.format(self.item_count as f64),
246250
format.display(self.total_size)
247251
);
248252
let selected = self.selected;
@@ -430,14 +434,15 @@ impl MarkPane {
430434
}
431435
}
432436

433-
pub fn calculate_size(marked: &EntryMarkMap) -> u128 {
437+
pub fn calculate_size_and_count(marked: &EntryMarkMap) -> (u128, u64) {
434438
let entries: Vec<&EntryMark> = marked
435439
.iter()
436440
.map(|(_k, v)| v)
437441
.sorted_by(|a, b| Ord::cmp(&a.path, &b.path))
438442
.collect();
439443

440444
let mut size = 0u128;
445+
let mut item_count = 0u64;
441446
for (idx, entry) in entries.iter().enumerate() {
442447
let mut is_subdirectory = false;
443448
for other in &entries[0..idx] {
@@ -448,9 +453,10 @@ pub fn calculate_size(marked: &EntryMarkMap) -> u128 {
448453
}
449454
if !is_subdirectory {
450455
size += entry.size;
456+
item_count += entry.entry_count.unwrap_or(1);
451457
}
452458
}
453-
size
459+
(size, item_count)
454460
}
455461

456462
#[cfg(test)]
@@ -475,6 +481,7 @@ mod mark_pane_tests {
475481
size: 10,
476482
path: PathBuf::from("root"),
477483
is_dir: true,
484+
entry_count: Some(2),
478485
..Default::default()
479486
},
480487
);
@@ -495,6 +502,6 @@ mod mark_pane_tests {
495502
},
496503
);
497504

498-
assert_eq!(calculate_size(&marked), 15u128);
505+
assert_eq!(calculate_size_and_count(&marked), (15u128, 3u64));
499506
}
500507
}

src/interactive/widgets/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ pub use header::*;
1111
pub use help::*;
1212
pub use main::*;
1313
pub use mark::*;
14+
use once_cell::sync::Lazy;
1415

1516
use tui::style::Color;
1617

1718
pub const COLOR_MARKED: Color = Color::Yellow;
1819
pub const COLOR_MARKED_DARK: Color = Color::Rgb(176, 126, 0);
1920

21+
static COUNT: Lazy<human_format::Formatter> = Lazy::new(|| {
22+
let mut formatter = human_format::Formatter::new();
23+
formatter.with_decimals(0).with_separator("");
24+
formatter
25+
});
26+
2027
fn entry_color(fg: Option<Color>, is_file: bool, is_marked: bool) -> Option<Color> {
2128
match (is_file, is_marked) {
2229
(true, false) => fg,

0 commit comments

Comments
 (0)