summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2024-01-03 22:02:31 +0100
committerqkzk <qu3nt1n@gmail.com>2024-01-03 22:04:19 +0100
commit2aa9e9a43eb84b95f98b4aadafd1b665397483d0 (patch)
tree7866823b4fa1d4f22a81599b13de365e6ea2a202 /src
parent173537ac0fc7081d03e3c96360de02da87f28a17 (diff)
clickable footer
Diffstat (limited to 'src')
-rw-r--r--src/app/header_footer.rs80
-rw-r--r--src/app/mod.rs2
-rw-r--r--src/io/display.rs5
3 files changed, 79 insertions, 8 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;
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;