summaryrefslogtreecommitdiffstats
path: root/src/interactive/mod.rs
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-15 13:20:28 +0800
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-15 13:21:11 +0800
commit1ce57a29c45ee9896bfc529a13875dbc3859812f (patch)
tree147f413b5b9104321196f5f587d0769ac5feff23 /src/interactive/mod.rs
parentafdbc1dadcf6c1f1e6384f65b2cac5325a5bcf17 (diff)
refactor
Diffstat (limited to 'src/interactive/mod.rs')
-rw-r--r--src/interactive/mod.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/interactive/mod.rs b/src/interactive/mod.rs
index ef02372..07c2036 100644
--- a/src/interactive/mod.rs
+++ b/src/interactive/mod.rs
@@ -3,5 +3,33 @@ pub mod widgets;
pub use self::app::*;
+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::*;
+
#[cfg(test)]
mod app_test;