diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-12-23 17:04:42 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-12-23 17:04:42 +0100 |
commit | 89bf9fc493d6460df046ac39a11b68033228a867 (patch) | |
tree | 8ae95777f99bcfbef4f0d633d4f62e09602455b6 | |
parent | 3589b77a067fdb489c88ad338703ce0674383948 (diff) |
display searched & filter in header, use more colors
-rw-r--r-- | src/app/header_footer.rs | 21 | ||||
-rw-r--r-- | src/io/display.rs | 43 |
2 files changed, 34 insertions, 30 deletions
diff --git a/src/app/header_footer.rs b/src/app/header_footer.rs index 9d2eb69..8415c23 100644 --- a/src/app/header_footer.rs +++ b/src/app/header_footer.rs @@ -4,9 +4,9 @@ mod inner { use crate::app::{Status, Tab}; use crate::event::ActionMap; - use crate::modes::Content; use crate::modes::Selectable; use crate::modes::{shorten_path, Display}; + use crate::modes::{Content, FilterKind}; /// Action for every element of the first line. /// It should match the order of the `FirstLine::make_string` static method. @@ -114,10 +114,25 @@ mod inner { /// 1. the length of the vector MUST BE the length of `ACTIONS` minus one. /// 2. the order must be respected. fn make_strings(tab: &Tab, width: usize) -> Result<Vec<String>> { - Ok(vec![ + let mut strings = vec![ Self::string_shorten_path(tab)?, Self::string_first_row_selected_file(tab, width)?, - ]) + ]; + if let Some(searched) = &tab.searched { + strings.push(Self::string_searched(searched)) + } + if !matches!(tab.settings.filter, FilterKind::All) { + strings.push(Self::string_filter(tab)) + } + Ok(strings) + } + + fn string_filter(tab: &Tab) -> String { + format!(" {filter} ", filter = tab.settings.filter.to_string()) + } + + fn string_searched(searched: &str) -> String { + format!(" Searched: {searched} ") } fn string_shorten_path(tab: &Tab) -> Result<String> { diff --git a/src/io/display.rs b/src/io/display.rs index 4d475d4..7eaa7ab 100644 --- a/src/io/display.rs +++ b/src/io/display.rs @@ -67,9 +67,11 @@ macro_rules! impl_preview { /// At least 120 chars width to display 2 tabs. pub const MIN_WIDTH_FOR_DUAL_PANE: usize = 120; -const FIRST_LINE_COLORS: [Attr; 2] = [ +const FIRST_LINE_COLORS: [Attr; 4] = [ color_to_attr(Color::LIGHT_CYAN), color_to_attr(Color::Rgb(230, 189, 87)), + color_to_attr(Color::Rgb(230, 167, 255)), + color_to_attr(Color::Rgb(59, 204, 255)), ]; const MENU_COLORS: [Attr; 10] = [ @@ -654,6 +656,7 @@ impl PreviewHeader { } } +#[derive(Default)] struct WinMainSecondLine { content: Option<String>, attr: Option<Attr>, @@ -671,40 +674,26 @@ impl Draw for WinMainSecondLine { impl WinMainSecondLine { fn new(status: &Status, tab: &Tab) -> Self { - let (content, attr) = match tab.display_mode { - DisplayMode::Directory | DisplayMode::Tree => { - if !status.display_settings.metadata() { - if let Ok(file) = tab.current_file() { - Self::second_line_detailed(&file) - } else { - (None, None) - } - } else { - Self::second_line_simple(status) - } - } - _ => (None, None), + if matches!(tab.display_mode, DisplayMode::Preview) || status.display_settings.metadata() { + return Self::default(); }; - Self { content, attr } + if let Ok(file) = tab.current_file() { + Self::second_line_detailed(&file) + } else { + Self::default() + } } - fn second_line_detailed(file: &FileInfo) -> (Option<String>, Option<Attr>) { + fn second_line_detailed(file: &FileInfo) -> Self { let owner_size = file.owner.len(); let group_size = file.group.len(); let mut attr = fileinfo_attr(file); attr.effect ^= Effect::REVERSE; - ( - Some(file.format(owner_size, group_size).unwrap_or_default()), - Some(attr), - ) - } - - fn second_line_simple(status: &Status) -> (Option<String>, Option<Attr>) { - ( - Some(status.current_tab().settings.filter.to_string()), - Some(ATTR_YELLOW_BOLD), - ) + Self { + content: Some(file.format(owner_size, group_size).unwrap_or_default()), + attr: Some(attr), + } } } |