summaryrefslogtreecommitdiffstats
path: root/src/interactive/mod.rs
blob: 81f8fa380fdb2ceb7e8b24bfd56a2b9a8bdebdd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mod app;
pub use app::*;

pub mod widgets;

mod utils {
    use dua::{
        get_entry_or_panic,
        traverse::{Tree, TreeIndex},
    };
    use std::path::PathBuf;

    pub fn path_of(tree: &Tree, mut node_idx: TreeIndex) -> PathBuf {
        const THE_ROOT: usize = 1;
        let mut entries = Vec::new();

        while let Some(parent_idx) = tree.neighbors_directed(node_idx, petgraph::Incoming).next() {
            entries.push(get_entry_or_panic(tree, node_idx));
            node_idx = parent_idx;
        }
        entries.push(get_entry_or_panic(tree, node_idx));
        entries
            .iter()
            .rev()
            .skip(THE_ROOT)
            .fold(PathBuf::new(), |mut acc, entry| {
                acc.push(&entry.name);
                acc
            })
    }
}
pub use utils::path_of;