Skip to content

Commit

Permalink
Added the feature to display fullscreen information on the second lin…
Browse files Browse the repository at this point in the history
…e of the status-bar.
  • Loading branch information
takezyou committed Sep 19, 2021
1 parent 6ec5195 commit a3b9338
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 7 deletions.
62 changes: 56 additions & 6 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ 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 = "";
static MORE_MSG: &str = " ... ";

#[derive(Default)]
struct State {
tabs: Vec<TabInfo>,
mode_info: ModeInfo,
diplay_text_copied_hint: bool,
}
Expand Down Expand Up @@ -137,6 +140,7 @@ impl ZellijPlugin for State {
set_selectable(false);
subscribe(&[
EventType::ModeUpdate,
EventType::TabUpdate,
EventType::CopyToClipboard,
EventType::InputReceived,
]);
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
79 changes: 79 additions & 0 deletions default-plugins/status-bar/src/second_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
6 changes: 6 additions & 0 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,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(),
});
}
Expand Down Expand Up @@ -489,6 +491,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);
Expand All @@ -497,6 +500,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);
Expand All @@ -505,6 +509,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();
Expand Down Expand Up @@ -635,6 +640,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;
Expand Down
5 changes: 4 additions & 1 deletion zellij-server/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub(crate) struct Tab {
pub position: usize,
pub name: String,
panes: BTreeMap<PaneId, Box<dyn Pane>>,
panes_to_hide: HashSet<PaneId>,
pub panes_to_hide: HashSet<PaneId>,
active_terminal: Option<PaneId>,
max_panes: Option<usize>,
viewport: Viewport, // includes all non-UI panes
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions zellij-tile/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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,
}

Expand Down

0 comments on commit a3b9338

Please sign in to comment.