diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-15 13:20:28 +0800 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-15 13:21:11 +0800 |
commit | 1ce57a29c45ee9896bfc529a13875dbc3859812f (patch) | |
tree | 147f413b5b9104321196f5f587d0769ac5feff23 /src/interactive | |
parent | afdbc1dadcf6c1f1e6384f65b2cac5325a5bcf17 (diff) |
refactor
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/app/common.rs | 2 | ||||
-rw-r--r-- | src/interactive/app/handlers.rs | 3 | ||||
-rw-r--r-- | src/interactive/mod.rs | 28 | ||||
-rw-r--r-- | src/interactive/widgets/entries.rs | 3 | ||||
-rw-r--r-- | src/interactive/widgets/mark.rs | 4 |
5 files changed, 33 insertions, 7 deletions
diff --git a/src/interactive/app/common.rs b/src/interactive/app/common.rs index 937276a..c612f28 100644 --- a/src/interactive/app/common.rs +++ b/src/interactive/app/common.rs @@ -1,4 +1,4 @@ -use dua::path_of; +use crate::interactive::path_of; use dua::traverse::{EntryData, Tree, TreeIndex}; use itertools::Itertools; use petgraph::Direction; diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index ad2b064..e9054aa 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -1,10 +1,9 @@ use crate::interactive::widgets::MarkMode; use crate::interactive::{ app::{FocussedPane::*, TerminalApp}, - sorted_entries, + path_of, sorted_entries, widgets::{HelpPane, MarkPane}, }; -use dua::path_of; use dua::traverse::TreeIndex; use itertools::Itertools; use petgraph::Direction; 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; diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs index cde0e5b..006673c 100644 --- a/src/interactive/widgets/entries.rs +++ b/src/interactive/widgets/entries.rs @@ -1,4 +1,5 @@ use crate::interactive::{ + path_of, widgets::{ EntryMarkMap, COLOR_BYTESIZE_SELECTED, COLOR_MARKED, COLOR_MARKED_DARK, COLOR_MARKED_DARKER, }, @@ -57,7 +58,7 @@ impl Entries { }; let total: u64 = entries.iter().map(|b| b.data.size).sum(); - let title = match dua::path_of(tree, *root).to_string_lossy().to_string() { + let title = match path_of(tree, *root).to_string_lossy().to_string() { ref p if p.is_empty() => Path::new(".") .canonicalize() .map(|p| p.to_string_lossy().to_string()) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 8faf784..688a48a 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -1,10 +1,9 @@ use crate::interactive::{ - fit_string_graphemes_with_ellipsis, + fit_string_graphemes_with_ellipsis, path_of, widgets::{COLOR_BYTESIZE_SELECTED, COLOR_MARKED_LIGHT}, CursorDirection, }; use dua::{ - path_of, traverse::{Tree, TreeIndex}, ByteFormat, }; @@ -311,7 +310,6 @@ impl MarkPane { fg: Color::Black, bg: Color::Yellow, modifier: Modifier::BOLD, - ..Default::default() }; Paragraph::new( [ |