diff options
Diffstat (limited to 'src/interactive/app')
-rw-r--r-- | src/interactive/app/common.rs | 19 | ||||
-rw-r--r-- | src/interactive/app/eventloop.rs | 1 | ||||
-rw-r--r-- | src/interactive/app/handlers.rs | 5 | ||||
-rw-r--r-- | src/interactive/app/tests/journeys_readonly.rs | 4 | ||||
-rw-r--r-- | src/interactive/app/tests/utils.rs | 63 |
5 files changed, 56 insertions, 36 deletions
diff --git a/src/interactive/app/common.rs b/src/interactive/app/common.rs index 805adc2..c977f4c 100644 --- a/src/interactive/app/common.rs +++ b/src/interactive/app/common.rs @@ -11,6 +11,8 @@ pub enum SortMode { SizeAscending, MTimeAscending, MTimeDescending, + CountAscending, + CountDescending, } impl SortMode { @@ -19,18 +21,25 @@ impl SortMode { *self = match self { SizeDescending => SizeAscending, SizeAscending => SizeDescending, - MTimeAscending => SizeAscending, - MTimeDescending => SizeDescending, + _ => SizeAscending, } } pub fn toggle_mtime(&mut self) { use SortMode::*; *self = match self { - SizeDescending => MTimeDescending, - SizeAscending => MTimeAscending, MTimeAscending => MTimeDescending, MTimeDescending => MTimeAscending, + _ => MTimeAscending, + } + } + + pub fn toggle_count(&mut self) { + use SortMode::*; + *self = match self { + CountAscending => CountDescending, + CountDescending => CountAscending, + _ => CountAscending, } } } @@ -62,6 +71,8 @@ pub fn sorted_entries(tree: &Tree, node_idx: TreeIndex, sorting: SortMode) -> Ve SizeAscending => l.data.size.cmp(&r.data.size), MTimeAscending => l.data.mtime.cmp(&r.data.mtime), MTimeDescending => r.data.mtime.cmp(&l.data.mtime), + CountAscending => l.data.entry_count.cmp(&r.data.entry_count), + CountDescending => r.data.entry_count.cmp(&l.data.entry_count), }) .collect() } diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index a8108bc..0502ddd 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -149,6 +149,7 @@ impl AppState { Ctrl('d') | PageDown => self.change_entry_selection(CursorDirection::PageDown), Char('s') => self.cycle_sorting(traversal), Char('m') => self.cycle_mtime_sorting(traversal), + Char('c') => self.cycle_count_sorting(traversal), Char('g') => display.byte_vis.cycle(), _ => {} }, diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index 4948c95..d3761e9 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -161,6 +161,11 @@ impl AppState { self.entries = sorted_entries(&traversal.tree, self.root, self.sorting); } + pub fn cycle_count_sorting(&mut self, traversal: &Traversal) { + self.sorting.toggle_count(); + self.entries = sorted_entries(&traversal.tree, self.root, self.sorting); + } + pub fn reset_message(&mut self) { if self.is_scanning { self.message = Some("-> scanning <-".into()); diff --git a/src/interactive/app/tests/journeys_readonly.rs b/src/interactive/app/tests/journeys_readonly.rs index c220a37..9bb4e27 100644 --- a/src/interactive/app/tests/journeys_readonly.rs +++ b/src/interactive/app/tests/journeys_readonly.rs @@ -67,14 +67,14 @@ fn simple_user_journey_read_only() -> Result<()> { app.process_events(&mut terminal, into_keys(b"m".iter()))?; assert_eq!( app.state.sorting, - SortMode::MTimeDescending, + SortMode::MTimeAscending, "it sets the sort mode to descending by mtime" ); // when hitting the M key again app.process_events(&mut terminal, into_keys(b"m".iter()))?; assert_eq!( app.state.sorting, - SortMode::MTimeAscending, + SortMode::MTimeDescending, "it sets the sort mode to ascending by mtime" ); // when hitting the S key diff --git a/src/interactive/app/tests/utils.rs b/src/interactive/app/tests/utils.rs index 7ca7382..68fc85b 100644 --- a/src/interactive/app/tests/utils.rs +++ b/src/interactive/app/tests/utils.rs @@ -224,32 +224,32 @@ pub fn sample_01_tree() -> Tree { let root_size = 1259070; #[cfg(windows)] let root_size = 1259069; - let rn = add_node("", root_size, None); + let rn = add_node("", root_size, 14, None); { - let sn = add_node(&fixture_str("sample-01"), root_size, Some(rn)); + let sn = add_node(&fixture_str("sample-01"), root_size, 13, Some(rn)); { - add_node(".hidden.666", 666, Some(sn)); - add_node("a", 256, Some(sn)); - add_node("b.empty", 0, Some(sn)); + add_node(".hidden.666", 666, 0, Some(sn)); + add_node("a", 256, 0, Some(sn)); + add_node("b.empty", 0, 0, Some(sn)); #[cfg(not(windows))] - add_node("c.lnk", 1, Some(sn)); + add_node("c.lnk", 1, 0, Some(sn)); #[cfg(windows)] - add_node("c.lnk", 0, Some(sn)); - let dn = add_node("dir", 1258024, Some(sn)); + add_node("c.lnk", 0, 0, Some(sn)); + let dn = add_node("dir", 1258024, 7, Some(sn)); { - add_node("1000bytes", 1000, Some(dn)); - add_node("dir-a.1mb", 1_000_000, Some(dn)); - add_node("dir-a.kb", 1024, Some(dn)); - let en = add_node("empty-dir", 0, Some(dn)); + add_node("1000bytes", 1000, 0, Some(dn)); + add_node("dir-a.1mb", 1_000_000, 0, Some(dn)); + add_node("dir-a.kb", 1024, 0, Some(dn)); + let en = add_node("empty-dir", 0, 1, Some(dn)); { - add_node(".gitkeep", 0, Some(en)); + add_node(".gitkeep", 0, 0, Some(en)); } - let sub = add_node("sub", 256_000, Some(dn)); + let sub = add_node("sub", 256_000, 1, Some(dn)); { - add_node("dir-sub-a.256kb", 256_000, Some(sub)); + add_node("dir-sub-a.256kb", 256_000, 0, Some(sub)); } } - add_node("z123.b", 123, Some(sn)); + add_node("z123.b", 123, 0, Some(sn)); } } } @@ -261,27 +261,28 @@ pub fn sample_02_tree() -> Tree { { let mut add_node = make_add_node(&mut tree); let root_size = 1540; - let rn = add_node("", root_size, None); + let rn = add_node("", root_size, 10, None); { let sn = add_node( Path::new(FIXTURE_PATH).join("sample-02").to_str().unwrap(), root_size, + 9, Some(rn), ); { - add_node("a", 256, Some(sn)); - add_node("b", 1, Some(sn)); - let dn = add_node("dir", 1283, Some(sn)); + add_node("a", 256, 0, Some(sn)); + add_node("b", 1, 0, Some(sn)); + let dn = add_node("dir", 1283, 6, Some(sn)); { - add_node("c", 257, Some(dn)); - add_node("d", 2, Some(dn)); - let en = add_node("empty-dir", 0, Some(dn)); + add_node("c", 257, 0, Some(dn)); + add_node("d", 2, 0, Some(dn)); + let en = add_node("empty-dir", 0, 1, Some(dn)); { - add_node(".gitkeep", 0, Some(en)); + add_node(".gitkeep", 0, 0, Some(en)); } - let sub = add_node("sub", 1024, Some(dn)); + let sub = add_node("sub", 1024, 1, Some(dn)); { - add_node("e", 1024, Some(sub)); + add_node("e", 1024, 0, Some(sub)); } } } @@ -290,13 +291,15 @@ pub fn sample_02_tree() -> Tree { tree } -pub fn make_add_node(t: &mut Tree) -> impl FnMut(&str, u128, Option<NodeIndex>) -> NodeIndex + '_ { - move |name, size, maybe_from_idx| { +pub fn make_add_node( + t: &mut Tree, +) -> impl FnMut(&str, u128, u64, Option<NodeIndex>) -> NodeIndex + '_ { + move |name, size, entry_count, maybe_from_idx| { let n = t.add_node(EntryData { name: PathBuf::from(name), size, - mtime: UNIX_EPOCH, - metadata_io_error: false, + entry_count, + ..Default::default() }); if let Some(from) = maybe_from_idx { t.add_edge(from, n, ()); |