diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-06-06 22:32:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-06 22:32:14 +0200 |
commit | 4a8d72d7b93ba881501fb04fa4d493631ad770b4 (patch) | |
tree | 616a0c4b90624583a7d64f48fb8a2d162800d187 /default-plugins/status-bar/src | |
parent | 627bb71f37f74d60a6a8722e238bdcad7d1e1cfb (diff) |
feat(ui): tweak simplified UI (#1458)
* fix(ui): tweak simplified-ui tabs
* fix(ui): tweak simplified-ui status bar
* style(fmt): rustfmt
Diffstat (limited to 'default-plugins/status-bar/src')
-rw-r--r-- | default-plugins/status-bar/src/first_line.rs | 133 | ||||
-rw-r--r-- | default-plugins/status-bar/src/main.rs | 93 |
2 files changed, 192 insertions, 34 deletions
diff --git a/default-plugins/status-bar/src/first_line.rs b/default-plugins/status-bar/src/first_line.rs index 7ca0b0fb6..dc7b95ecc 100644 --- a/default-plugins/status-bar/src/first_line.rs +++ b/default-plugins/status-bar/src/first_line.rs @@ -28,6 +28,7 @@ enum CtrlKeyAction { enum CtrlKeyMode { Unselected, + UnselectedAlternate, Selected, Disabled, } @@ -85,6 +86,40 @@ fn unselected_mode_shortcut( } } +fn unselected_alternate_mode_shortcut( + letter: char, + text: &str, + palette: ColoredElements, + separator: &str, +) -> LinePart { + let prefix_separator = palette + .unselected_alternate_prefix_separator + .paint(separator); + let char_left_separator = palette.unselected_alternate_char_left_separator.paint(" <"); + let char_shortcut = palette + .unselected_alternate_char_shortcut + .paint(letter.to_string()); + let char_right_separator = palette.unselected_alternate_char_right_separator.paint(">"); + let styled_text = palette + .unselected_alternate_styled_text + .paint(format!("{} ", text)); + let suffix_separator = palette + .unselected_alternate_suffix_separator + .paint(separator); + LinePart { + part: ANSIStrings(&[ + prefix_separator, + char_left_separator, + char_shortcut, + char_right_separator, + styled_text, + suffix_separator, + ]) + .to_string(), + len: text.chars().count() + 7, // 2 for the arrows, 3 for the char separators, 1 for the character, 1 for the text padding + } +} + fn selected_mode_shortcut( letter: char, text: &str, @@ -165,6 +200,28 @@ fn unselected_mode_shortcut_single_letter( } } +fn unselected_alternate_mode_shortcut_single_letter( + letter: char, + palette: ColoredElements, + separator: &str, +) -> LinePart { + let char_shortcut_text = format!(" {} ", letter); + let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding + let prefix_separator = palette + .unselected_alternate_single_letter_prefix_separator + .paint(separator); + let char_shortcut = palette + .unselected_alternate_single_letter_char_shortcut + .paint(char_shortcut_text); + let suffix_separator = palette + .unselected_alternate_single_letter_suffix_separator + .paint(separator); + LinePart { + part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(), + len, + } +} + fn full_ctrl_key(key: &CtrlKeyShortcut, palette: ColoredElements, separator: &str) -> LinePart { let full_text = key.full_text(); let letter_shortcut = key.letter_shortcut(); @@ -175,6 +232,12 @@ fn full_ctrl_key(key: &CtrlKeyShortcut, palette: ColoredElements, separator: &st palette, separator, ), + CtrlKeyMode::UnselectedAlternate => unselected_alternate_mode_shortcut( + letter_shortcut, + &format!(" {}", full_text), + palette, + separator, + ), CtrlKeyMode::Selected => selected_mode_shortcut( letter_shortcut, &format!(" {}", full_text), @@ -199,6 +262,9 @@ fn single_letter_ctrl_key( CtrlKeyMode::Unselected => { unselected_mode_shortcut_single_letter(letter_shortcut, palette, separator) } + CtrlKeyMode::UnselectedAlternate => { + unselected_alternate_mode_shortcut_single_letter(letter_shortcut, palette, separator) + } CtrlKeyMode::Selected => { selected_mode_shortcut_single_letter(letter_shortcut, palette, separator) } @@ -237,7 +303,11 @@ fn key_indicators( } pub fn superkey(palette: ColoredElements, separator: &str) -> LinePart { - let prefix_text = " Ctrl +"; + let prefix_text = if separator.len() == 0 { + " Ctrl + " + } else { + " Ctrl +" + }; let prefix = palette.superkey_prefix.paint(prefix_text); let suffix_separator = palette.superkey_suffix_separator.paint(separator); LinePart { @@ -247,7 +317,8 @@ pub fn superkey(palette: ColoredElements, separator: &str) -> LinePart { } pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { - let colored_elements = color_elements(help.style.colors); + let supports_arrow_fonts = !help.capabilities.arrow_fonts; + let colored_elements = color_elements(help.style.colors, !supports_arrow_fonts); match &help.mode { InputMode::Locked => key_indicators( max_len, @@ -268,13 +339,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -285,11 +356,11 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -298,13 +369,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -313,13 +384,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -328,13 +399,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -343,13 +414,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -358,13 +429,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, @@ -373,13 +444,13 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { max_len, &[ CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Scroll), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + CtrlKeyShortcut::new(CtrlKeyMode::UnselectedAlternate, CtrlKeyAction::Quit), ], colored_elements, separator, diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 7c741853a..7257556bc 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -59,6 +59,13 @@ pub struct ColoredElements { pub unselected_char_right_separator: Style, pub unselected_styled_text: Style, pub unselected_suffix_separator: Style, + // unselected mode alternate color + pub unselected_alternate_prefix_separator: Style, + pub unselected_alternate_char_left_separator: Style, + pub unselected_alternate_char_shortcut: Style, + pub unselected_alternate_char_right_separator: Style, + pub unselected_alternate_styled_text: Style, + pub unselected_alternate_suffix_separator: Style, // disabled mode pub disabled_prefix_separator: Style, pub disabled_styled_text: Style, @@ -71,6 +78,10 @@ pub struct ColoredElements { pub unselected_single_letter_prefix_separator: Style, pub unselected_single_letter_char_shortcut: Style, pub unselected_single_letter_suffix_separator: Style, + // unselected alternate single letter + pub unselected_alternate_single_letter_prefix_separator: Style, + pub unselected_alternate_single_letter_char_shortcut: Style, + pub unselected_alternate_single_letter_suffix_separator: Style, // superkey pub superkey_prefix: Style, pub superkey_suffix_separator: Style, @@ -80,7 +91,7 @@ pub struct ColoredElements { // we need different colors from palette for the default theme // plus here we can add new sources in the future, like Theme // that can be defined in the config perhaps -fn color_elements(palette: Palette) -> ColoredElements { +fn color_elements(palette: Palette, different_color_alternates: bool) -> ColoredElements { let background = match palette.theme_hue { ThemeHue::Dark => palette.black, ThemeHue::Light => palette.white, @@ -89,6 +100,14 @@ fn color_elements(palette: Palette) -> ColoredElements { ThemeHue::Dark => palette.white, ThemeHue::Light => palette.black, }; + let alternate_background_color = if different_color_alternates { + match palette.theme_hue { + ThemeHue::Dark => palette.white, + ThemeHue::Light => palette.black, + } + } else { + palette.fg + }; match palette.source { PaletteSource::Default => ColoredElements { selected_prefix_separator: style!(background, palette.green), @@ -97,21 +116,55 @@ fn color_elements(palette: Palette) -> ColoredElements { selected_char_right_separator: style!(background, palette.green).bold(), selected_styled_text: style!(background, palette.green).bold(), selected_suffix_separator: style!(palette.green, background).bold(), + unselected_prefix_separator: style!(background, palette.fg), unselected_char_left_separator: style!(background, palette.fg).bold(), unselected_char_shortcut: style!(palette.red, palette.fg).bold(), unselected_char_right_separator: style!(background, palette.fg).bold(), unselected_styled_text: style!(background, palette.fg).bold(), unselected_suffix_separator: style!(palette.fg, background), + + unselected_alternate_prefix_separator: style!(background, alternate_background_color), + unselected_alternate_char_left_separator: style!( + background, + alternate_background_color + ) + .bold(), + unselected_alternate_char_shortcut: style!(palette.red, alternate_background_color) + .bold(), + unselected_alternate_char_right_separator: style!( + background, + alternate_background_color + ) + .bold(), + unselected_alternate_styled_text: style!(background, alternate_background_color).bold(), + unselected_alternate_suffix_separator: style!(alternate_background_color, background), + disabled_prefix_separator: style!(background, palette.fg), disabled_styled_text: style!(background, palette.fg).dimmed().italic(), disabled_suffix_separator: style!(palette.fg, background), selected_single_letter_prefix_separator: style!(background, palette.green), selected_single_letter_char_shortcut: style!(palette.red, palette.green).bold(), selected_single_letter_suffix_separator: style!(palette.green, background), + unselected_single_letter_prefix_separator: style!(background, palette.fg), unselected_single_letter_char_shortcut: style!(palette.red, palette.fg).bold().dimmed(), unselected_single_letter_suffix_separator: style!(palette.fg, background), + + unselected_alternate_single_letter_prefix_separator: style!( + palette.fg, + alternate_background_color + ), + unselected_alternate_single_letter_char_shortcut: style!( + palette.red, + alternate_background_color + ) + .bold(), + unselected_alternate_single_letter_suffix_separator: style!( + palette.fg, + alternate_background_color + ), + superkey_prefix: style!(foreground, background).bold(), superkey_suffix_separator: style!(background, background), }, @@ -128,15 +181,48 @@ fn color_elements(palette: Palette) -> ColoredElements { unselected_char_right_separator: style!(background, palette.fg).bold(), unselected_styled_text: style!(background, palette.fg).bold(), unselected_suffix_separator: style!(palette.fg, background), + + unselected_alternate_prefix_separator: style!(background, alternate_background_color), + unselected_alternate_char_left_separator: style!( + background, + alternate_background_color + ) + .bold(), + unselected_alternate_char_shortcut: style!(palette.red, alternate_background_color) + .bold(), + unselected_alternate_char_right_separator: style!( + background, + alternate_background_color + ) + .bold(), + unselected_alternate_styled_text: style!(background, alternate_background_color).bold(), + unselected_alternate_suffix_separator: style!(alternate_background_color, background), + disabled_prefix_separator: style!(background, palette.fg), disabled_styled_text: style!(background, palette.fg).dimmed(), disabled_suffix_separator: style!(palette.fg, background), selected_single_letter_prefix_separator: style!(palette.fg, palette.green), selected_single_letter_char_shortcut: style!(palette.red, palette.green).bold(), selected_single_letter_suffix_separator: style!(palette.green, palette.fg), + unselected_single_letter_prefix_separator: style!(palette.fg, background), unselected_single_letter_char_shortcut: style!(palette.red, palette.fg).bold(), unselected_single_letter_suffix_separator: style!(palette.fg, background), + + unselected_alternate_single_letter_prefix_separator: style!( + palette.fg, + alternate_background_color + ), + unselected_alternate_single_letter_char_shortcut: style!( + palette.red, + alternate_background_color + ) + .bold(), + unselected_alternate_single_letter_suffix_separator: style!( + palette.fg, + alternate_background_color + ), + superkey_prefix: style!(background, palette.fg).bold(), superkey_suffix_separator: style!(palette.fg, background), }, @@ -180,13 +266,14 @@ impl ZellijPlugin for State { } fn render(&mut self, _rows: usize, cols: usize) { - let separator = if !self.mode_info.capabilities.arrow_fonts { + let supports_arrow_fonts = !self.mode_info.capabilities.arrow_fonts; + let separator = if supports_arrow_fonts { ARROW_SEPARATOR } else { "" }; - let colored_elements = color_elements(self.mode_info.style.colors); + let colored_elements = color_elements(self.mode_info.style.colors, !supports_arrow_fonts); let superkey = superkey(colored_elements, separator); let ctrl_keys = ctrl_keys( &self.mode_info, |