|
1 | | -use crate::{ |
2 | | - interactive::SortMode, |
3 | | - traverse::{EntryData, Tree, TreeIndex}, |
4 | | -}; |
| 1 | +use crate::traverse::{EntryData, Tree, TreeIndex}; |
5 | 2 | use byte_unit::{n_gb_bytes, n_gib_bytes, n_mb_bytes, n_mib_bytes, ByteUnit}; |
6 | 3 | use itertools::Itertools; |
7 | 4 | use jwalk::WalkDir; |
8 | 5 | use petgraph::Direction; |
9 | 6 | use std::{fmt, path::Path, path::PathBuf}; |
10 | 7 |
|
11 | | -pub(crate) fn path_of(tree: &Tree, mut node_idx: TreeIndex) -> PathBuf { |
| 8 | +#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq)] |
| 9 | +pub enum SortMode { |
| 10 | + SizeDescending, |
| 11 | + SizeAscending, |
| 12 | +} |
| 13 | + |
| 14 | +impl SortMode { |
| 15 | + pub fn toggle_size(&mut self) { |
| 16 | + use SortMode::*; |
| 17 | + *self = match self { |
| 18 | + SizeAscending => SizeDescending, |
| 19 | + SizeDescending => SizeAscending, |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +impl Default for SortMode { |
| 25 | + fn default() -> Self { |
| 26 | + SortMode::SizeDescending |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +pub fn path_of(tree: &Tree, mut node_idx: TreeIndex) -> PathBuf { |
12 | 31 | const THE_ROOT: usize = 1; |
13 | 32 | let mut entries = Vec::new(); |
14 | 33 |
|
@@ -36,7 +55,7 @@ pub(crate) fn get_size_or_panic(tree: &Tree, node_idx: TreeIndex) -> u64 { |
36 | 55 | get_entry_or_panic(tree, node_idx).size |
37 | 56 | } |
38 | 57 |
|
39 | | -pub(crate) fn sorted_entries( |
| 58 | +pub fn sorted_entries( |
40 | 59 | tree: &Tree, |
41 | 60 | node_idx: TreeIndex, |
42 | 61 | sorting: SortMode, |
|
0 commit comments