diff options
author | qkzk <qu3nt1n@gmail.com> | 2024-01-03 22:02:31 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2024-01-03 22:04:19 +0100 |
commit | 2aa9e9a43eb84b95f98b4aadafd1b665397483d0 (patch) | |
tree | 7866823b4fa1d4f22a81599b13de365e6ea2a202 /src/app | |
parent | 173537ac0fc7081d03e3c96360de02da87f28a17 (diff) |
clickable footer
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/header_footer.rs | 80 | ||||
-rw-r--r-- | src/app/mod.rs | 2 |
2 files changed, 75 insertions, 7 deletions
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; |