diff options
-rw-r--r-- | development.md | 2 | ||||
-rw-r--r-- | src/app/header_footer.rs | 80 | ||||
-rw-r--r-- | src/app/mod.rs | 2 | ||||
-rw-r--r-- | src/io/display.rs | 5 |
4 files changed, 81 insertions, 8 deletions
diff --git a/development.md b/development.md index 1e8655c..b65331e 100644 --- a/development.md +++ b/development.md @@ -788,6 +788,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] simplest possible holding struct - [x] another display mode, displayable - [x] display flagged like in dir + - [x] clickable header & footer - [ ] enter: from skim files or lines, from flagged, from search, from folder, from tree (flatten) - [ ] action on all files - [x] renaming crashes (requires a lot..) @@ -796,6 +797,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] jump with enter - [x] space toggle flag like elsewhere - [x] ctrl+o open all fuzzy files + - [ ] flag / unflag all (u, v) - [ ] FIX: bulkrename. Either leave or capture all new names & update flagged ## TODO diff --git a/src/app/header_footer.rs b/src/app/header_footer.rs index 4b454a1..14d9214 100644 --- a/src/app/header_footer.rs +++ b/src/app/header_footer.rs @@ -292,23 +292,22 @@ mod inner { pub struct FuzzyHeader { strings: Vec<String>, - actions: Vec<ActionMap>, sizes: Vec<usize>, width: usize, } impl FuzzyHeader { + const ACTIONS: [ActionMap; 2] = [ActionMap::ResetMode, ActionMap::OpenFile]; + pub fn new(status: &Status, tab: &Tab) -> Result<Self> { let strings = Self::make_strings(tab); let sizes = Self::make_sizes(&strings); let (width, _) = status.internal_settings.term.term_size()?; - let actions = vec![ActionMap::ResetMode, ActionMap::OpenFile]; Ok(Self { strings, sizes, width, - actions, }) } @@ -324,11 +323,14 @@ mod inner { } fn make_sizes(strings: &[String]) -> Vec<usize> { - strings.iter().map(|s| s.len()).collect() + strings + .iter() + .map(|s| s.graphemes(true).collect::<Vec<&str>>().iter().len()) + .collect() } fn actions(&self, index: usize) -> &ActionMap { - &self.actions[index] + &Self::ACTIONS[index] } } @@ -352,6 +354,72 @@ mod inner { self.width } } + pub struct FuzzyFooter { + strings: Vec<String>, + sizes: Vec<usize>, + width: usize, + } + + impl ClickableLine for FuzzyFooter { + /// Vector of displayed strings. + fn strings(&self) -> &Vec<String> { + self.strings.as_ref() + } + } + + impl ClickableLineInner for FuzzyFooter { + fn sizes(&self) -> &Vec<usize> { + self.sizes.as_ref() + } + + fn action_index(&self, index: usize) -> &ActionMap { + &Self::ACTIONS[index] + } + + fn width(&self) -> usize { + self.width + } + } + + impl FuzzyFooter { + const ACTIONS: [ActionMap; 2] = [ActionMap::Nothing, ActionMap::Jump]; + + pub fn new(status: &Status, tab: &Tab) -> Result<Self> { + let (width, _) = status.internal_settings.term.term_size()?; + let used_width = if status.display_settings.use_dual_tab(width) { + width / 2 + } else { + width + }; + let raw_strings = Self::make_strings(status, tab); + let sizes = Self::make_sizes(&raw_strings); + let strings = Footer::make_padded_strings(&raw_strings, used_width); + + Ok(Self { + strings, + sizes, + width, + }) + } + + fn make_strings(status: &Status, tab: &Tab) -> Vec<String> { + vec![ + format!( + " {index} / {len}", + index = tab.fuzzy.index + 1, + len = tab.fuzzy.len() + ), + format!(" {nb} flags", nb = status.menu.flagged.len()), + ] + } + + fn make_sizes(strings: &[String]) -> Vec<usize> { + strings + .iter() + .map(|s| s.graphemes(true).collect::<Vec<&str>>().iter().len()) + .collect() + } + } } -pub use inner::{ClickableLine, Footer, FuzzyHeader, Header}; +pub use inner::{ClickableLine, Footer, FuzzyFooter, FuzzyHeader, Header}; diff --git a/src/app/mod.rs b/src/app/mod.rs index bc914a0..4437451 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -9,7 +9,7 @@ mod tab; pub use application::FM; pub use displayer::Displayer; -pub use header_footer::{ClickableLine, Footer, FuzzyHeader, Header}; +pub use header_footer::{ClickableLine, Footer, FuzzyFooter, FuzzyHeader, Header}; pub use internal_settings::InternalSettings; pub use refresher::Refresher; pub use session::Session; diff --git a/src/io/display.rs b/src/io/display.rs index d4269c0..4211b74 100644 --- a/src/io/display.rs +++ b/src/io/display.rs @@ -11,7 +11,7 @@ use crate::app::Footer; use crate::app::Header; use crate::app::Status; use crate::app::Tab; -use crate::app::{ClickableLine, FuzzyHeader}; +use crate::app::{ClickableLine, FuzzyFooter, FuzzyHeader}; use crate::common::path_to_string; use crate::common::{ ENCRYPTED_DEVICE_BINDS, HELP_FIRST_SENTENCE, HELP_SECOND_SENTENCE, LOG_FIRST_SENTENCE, @@ -750,6 +750,9 @@ impl<'a> Draw for WinMainFooter<'a> { let height = canvas.height()?; let content = match self.tab.display_mode { DisplayMode::Preview => vec![], + DisplayMode::Fuzzy => FuzzyFooter::new(self.status, self.tab)? + .strings() + .to_owned(), _ => Footer::new(self.status, self.tab)?.strings().to_owned(), }; let mut attr = ATTR_COB_BOLD; |