diff options
Diffstat (limited to 'src/interactive/app/app_state.rs')
-rw-r--r-- | src/interactive/app/app_state.rs | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/src/interactive/app/app_state.rs b/src/interactive/app/app_state.rs index dd0f9a0..8986f09 100644 --- a/src/interactive/app/app_state.rs +++ b/src/interactive/app/app_state.rs @@ -1,4 +1,5 @@ -use dua::WalkResult; +use dua::{WalkResult, traverse::{TreeIndex, Tree}, inodefilter::InodeFilter}; +use petgraph::Direction; use super::{navigation::Navigation, EntryDataBundle, SortMode}; @@ -27,6 +28,73 @@ pub struct AppState { pub message: Option<String>, pub focussed: FocussedPane, pub is_scanning: bool, + pub traversal_state: TraversalState, +} + + +#[derive(Default)] +pub struct TraversalState { + pub previous_node_idx: TreeIndex, + pub parent_node_idx: TreeIndex, + pub directory_info_per_depth_level: Vec<EntryInfo>, + pub current_directory_at_depth: EntryInfo, + pub previous_depth: usize, + pub inodes: InodeFilter, +} + +impl TraversalState { + pub fn new(root_idx: TreeIndex) -> Self { + Self { + previous_node_idx: root_idx, + parent_node_idx: root_idx, + directory_info_per_depth_level: Vec::new(), + current_directory_at_depth: EntryInfo::default(), + previous_depth: 0, + inodes: InodeFilter::default(), + } + } +} + +#[derive(Default, Copy, Clone)] +pub struct EntryInfo { + pub size: u128, + pub entries_count: Option<u64>, +} + +impl EntryInfo { + pub fn add_count(&mut self, other: &Self) { + self.entries_count = match (self.entries_count, other.entries_count) { + (Some(a), Some(b)) => Some(a + b), + (None, Some(b)) => Some(b), + (Some(a), None) => Some(a), + (None, None) => None, + }; + } +} + +pub fn set_entry_info_or_panic( + tree: &mut Tree, + node_idx: TreeIndex, + EntryInfo { + size, + entries_count, + }: EntryInfo, +) { + let node = tree + .node_weight_mut(node_idx) + .expect("node for parent index we just retrieved"); + node.size = size; + node.entry_count = entries_count; +} + +pub fn parent_or_panic(tree: &mut Tree, parent_node_idx: TreeIndex) -> TreeIndex { + tree.neighbors_directed(parent_node_idx, Direction::Incoming) + .next() + .expect("every node in the iteration has a parent") +} + +pub fn pop_or_panic(v: &mut Vec<EntryInfo>) -> EntryInfo { + v.pop().expect("sizes per level to be in sync with graph") } pub enum ProcessingResult { |