diff --git a/default-plugins/status-bar/src/main.rs b/default-plugins/status-bar/src/main.rs index 9f8e9eaa..f1b2197e 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, 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 d73cb287..0e59fcb8 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, + } +} diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 01bdc990..e1e743f1 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -369,6 +369,8 @@ impl Screen { position: tab.position, name: tab.name.clone(), active: active_tab_index == tab.index, + panes_to_hide: tab.panes_to_hide.len(), + is_fullscreen_active: tab.is_fullscreen_active(), is_sync_panes_active: tab.is_sync_panes_active(), }); } @@ -487,6 +489,7 @@ pub(crate) fn screen_thread_main( .senders .send_to_server(ServerInstruction::UnblockInputThread) .unwrap(); + screen.update_tabs(); } ScreenInstruction::HorizontalSplit(pid) => { screen.get_active_tab_mut().unwrap().horizontal_split(pid); @@ -495,6 +498,7 @@ pub(crate) fn screen_thread_main( .senders .send_to_server(ServerInstruction::UnblockInputThread) .unwrap(); + screen.update_tabs(); } ScreenInstruction::VerticalSplit(pid) => { screen.get_active_tab_mut().unwrap().vertical_split(pid); @@ -503,6 +507,7 @@ pub(crate) fn screen_thread_main( .senders .send_to_server(ServerInstruction::UnblockInputThread) .unwrap(); + screen.update_tabs(); } ScreenInstruction::WriteCharacter(bytes) => { let active_tab = screen.get_active_tab_mut().unwrap(); @@ -633,6 +638,7 @@ pub(crate) fn screen_thread_main( .get_active_tab_mut() .unwrap() .toggle_active_pane_fullscreen(); + screen.update_tabs(); } ScreenInstruction::TogglePaneFrames => { screen.draw_pane_frames = !screen.draw_pane_frames; diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index 92085955..2e307341 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -99,7 +99,7 @@ pub(crate) struct Tab { pub position: usize, pub name: String, panes: BTreeMap>, - panes_to_hide: HashSet, + pub panes_to_hide: HashSet, active_terminal: Option, max_panes: Option, viewport: Viewport, // includes all non-UI panes @@ -658,6 +658,9 @@ impl Tab { self.toggle_fullscreen_is_active(); } } + pub fn is_fullscreen_active(&self) -> bool { + self.fullscreen_is_active + } pub fn toggle_fullscreen_is_active(&mut self) { self.fullscreen_is_active = !self.fullscreen_is_active; } diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index 6ca70c28..3e5062b9 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -161,6 +161,8 @@ pub struct TabInfo { pub position: usize, pub name: String, pub active: bool, + pub panes_to_hide: usize, + pub is_fullscreen_active: bool, pub is_sync_panes_active: bool, }