diff options
Diffstat (limited to 'default-plugins')
-rw-r--r-- | default-plugins/status-bar/src/main.rs | 62 | ||||
-rw-r--r-- | default-plugins/status-bar/src/second_line.rs | 79 |
2 files changed, 135 insertions, 6 deletions
diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 9f8e9eaab..f1b2197e4 100644 --- a/default-plugins/status-bar/src/main.rs +++ b/default-plugins/status-bar/src/main.rs @@ -8,7 +8,9 @@ use zellij_tile::prelude::*; use zellij_tile_utils::style; use first_line::{ctrl_keys, superkey}; -use second_line::{keybinds, text_copied_hint}; +use second_line::{ + fullscreen_panes_to_hide, keybinds, locked_fullscreen_panes_to_hide, text_copied_hint, +}; // for more of these, copy paste from: https://en.wikipedia.org/wiki/Box-drawing_character static ARROW_SEPARATOR: &str = ""; @@ -16,6 +18,7 @@ static MORE_MSG: &str = " ... "; #[derive(Default)] struct State { + tabs: Vec<TabInfo>, mode_info: ModeInfo, diplay_text_copied_hint: bool, } @@ -137,6 +140,7 @@ impl ZellijPlugin for State { set_selectable(false); subscribe(&[ EventType::ModeUpdate, + EventType::TabUpdate, EventType::CopyToClipboard, EventType::InputReceived, ]); @@ -147,6 +151,9 @@ impl ZellijPlugin for State { Event::ModeUpdate(mode_info) => { self.mode_info = mode_info; } + Event::TabUpdate(tabs) => { + self.tabs = tabs; + } Event::CopyToClipboard => { self.diplay_text_copied_hint = true; } @@ -173,11 +180,54 @@ impl ZellijPlugin for State { ); let first_line = format!("{}{}", superkey, ctrl_keys); - let second_line = if self.diplay_text_copied_hint { - text_copied_hint(&self.mode_info.palette) - } else { - keybinds(&self.mode_info, cols) - }; + + let mut second_line = LinePart::default(); + for t in self.tabs.iter_mut() { + if t.active { + match self.mode_info.mode { + InputMode::Normal => { + if t.is_fullscreen_active { + second_line = if self.diplay_text_copied_hint { + text_copied_hint(&self.mode_info.palette) + } else { + fullscreen_panes_to_hide(&self.mode_info.palette, t.panes_to_hide) + } + } else { + second_line = if self.diplay_text_copied_hint { + text_copied_hint(&self.mode_info.palette) + } else { + keybinds(&self.mode_info, cols) + } + } + } + InputMode::Locked => { + if t.is_fullscreen_active { + second_line = if self.diplay_text_copied_hint { + text_copied_hint(&self.mode_info.palette) + } else { + locked_fullscreen_panes_to_hide( + &self.mode_info.palette, + t.panes_to_hide, + ) + } + } else { + second_line = if self.diplay_text_copied_hint { + text_copied_hint(&self.mode_info.palette) + } else { + keybinds(&self.mode_info, cols) + } + } + } + _ => { + second_line = if self.diplay_text_copied_hint { + text_copied_hint(&self.mode_info.palette) + } else { + keybinds(&self.mode_info, cols) + } + } + } + } + } // [48;5;238m is gray background, [0K is so that it fills the rest of the line // [m is background reset, [0K is so that it clears the rest of the line diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs index d73cb2874..0e59fcb8e 100644 --- a/default-plugins/status-bar/src/second_line.rs +++ b/default-plugins/status-bar/src/second_line.rs @@ -387,3 +387,82 @@ pub fn text_copied_hint(palette: &Palette) -> LinePart { len: hint.len(), } } + +pub fn fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> LinePart { + let white_color = match palette.white { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let green_color = match palette.green { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let orange_color = match palette.orange { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" ("); + let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): "); + let fullscreen = "FULLSCREEN"; + let puls = "+ "; + let panes = panes_to_hide.to_string(); + let hide = " hidden panes"; + let len = fullscreen.chars().count() + + puls.chars().count() + + panes.chars().count() + + hide.chars().count() + + 5; // 3 for ():'s around shortcut, 2 for the space + LinePart { + part: format!( + "{}{}{}{}{}{}", + shortcut_left_separator, + Style::new().fg(orange_color).bold().paint(fullscreen), + shortcut_right_separator, + Style::new().fg(white_color).bold().paint(puls), + Style::new().fg(green_color).bold().paint(panes), + Style::new().fg(white_color).bold().paint(hide) + ), + len, + } +} + +pub fn locked_fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> LinePart { + let white_color = match palette.white { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let green_color = match palette.green { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let orange_color = match palette.orange { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let locked_text = " -- INTERFACE LOCKED -- "; + let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" ("); + let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): "); + let fullscreen = "FULLSCREEN"; + let puls = "+ "; + let panes = panes_to_hide.to_string(); + let hide = " hidden panes"; + let len = locked_text.chars().count() + + fullscreen.chars().count() + + puls.chars().count() + + panes.chars().count() + + hide.chars().count() + + 5; // 3 for ():'s around shortcut, 2 for the space + LinePart { + part: format!( + "{}{}{}{}{}{}{}", + Style::new().fg(white_color).bold().paint(locked_text), + shortcut_left_separator, + Style::new().fg(orange_color).bold().paint(fullscreen), + shortcut_right_separator, + Style::new().fg(white_color).bold().paint(puls), + Style::new().fg(green_color).bold().paint(panes), + Style::new().fg(white_color).bold().paint(hide) + ), + len, + } +} |