Skip to content

Commit

Permalink
feat(ui): new status bar mode (zellij-org#2619)
Browse files Browse the repository at this point in the history
* supermode prototype

* fix integration tests

* fix tests

* style(fmt): rustfmt
  • Loading branch information
imsnif committed Jul 12, 2023
1 parent 61f3789 commit 27763d2
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 173 deletions.
367 changes: 333 additions & 34 deletions default-plugins/status-bar/src/first_line.rs

Large diffs are not rendered by default.

81 changes: 69 additions & 12 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use zellij_tile::prelude::actions::Action;
use zellij_tile::prelude::*;
use zellij_tile_utils::{palette_match, style};

use first_line::first_line;
use first_line::{first_line, first_line_supermode};
use second_line::{
floating_panes_are_visible, fullscreen_panes_to_hide, keybinds,
locked_floating_panes_are_visible, locked_fullscreen_panes_to_hide, system_clipboard_error,
floating_panes_are_visible, fullscreen_panes_to_hide, keybinds, system_clipboard_error,
text_copied_hint,
};
use tip::utils::get_cached_tip_name;
Expand All @@ -34,6 +33,10 @@ struct State {
mode_info: ModeInfo,
text_copy_destination: Option<CopyDestination>,
display_system_clipboard_failure: bool,

supermode: bool,
standby_mode: InputMode,
current_mode: InputMode,
}

register_plugin!(State);
Expand All @@ -60,6 +63,7 @@ impl Display for LinePart {
#[derive(Clone, Copy)]
pub struct ColoredElements {
pub selected: SegmentStyle,
pub selected_standby_shortcut: SegmentStyle,
pub unselected: SegmentStyle,
pub unselected_alternate: SegmentStyle,
pub disabled: SegmentStyle,
Expand Down Expand Up @@ -109,6 +113,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
styled_text: style!(background, palette.green).bold(),
suffix_separator: style!(palette.green, background).bold(),
},
selected_standby_shortcut: SegmentStyle {
prefix_separator: style!(background, palette.green),
char_left_separator: style!(background, palette.green).bold(),
char_shortcut: style!(palette.red, palette.green).bold(),
char_right_separator: style!(background, palette.green).bold(),
styled_text: style!(background, palette.green).bold(),
suffix_separator: style!(palette.green, palette.fg).bold(),
},
unselected: SegmentStyle {
prefix_separator: style!(background, palette.fg),
char_left_separator: style!(background, palette.fg).bold(),
Expand Down Expand Up @@ -145,6 +157,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
styled_text: style!(background, palette.green).bold(),
suffix_separator: style!(palette.green, background).bold(),
},
selected_standby_shortcut: SegmentStyle {
prefix_separator: style!(background, palette.green),
char_left_separator: style!(background, palette.green).bold(),
char_shortcut: style!(palette.red, palette.green).bold(),
char_right_separator: style!(background, palette.green).bold(),
styled_text: style!(background, palette.green).bold(),
suffix_separator: style!(palette.green, palette.fg).bold(),
},
unselected: SegmentStyle {
prefix_separator: style!(background, palette.fg),
char_left_separator: style!(background, palette.fg).bold(),
Expand Down Expand Up @@ -187,12 +207,44 @@ impl ZellijPlugin for State {
EventType::InputReceived,
EventType::SystemClipboardFailure,
]);
self.supermode = false; // TODO: from config
self.standby_mode = InputMode::Pane;
if self.supermode {
switch_to_input_mode(&InputMode::Locked); // supermode should start locked (TODO: only
// once per app load, let's not do this on
// each tab loading)
}
}

fn update(&mut self, event: Event) -> bool {
let mut should_render = false;
match event {
Event::ModeUpdate(mode_info) => {
if self.supermode {
// supermode is a "sticky" mode that is not Normal or Locked
// using this configuration, we default to Locked mode in order to avoid key
// collisions with terminal applications
// whenever the user switches away from locked mode, we make sure to place them
// in the standby mode
// whenever the user switches to a mode that is not locked or normal, we set
// that mode as the standby mode
// whenever the user switches away from the standby mode, we palce them in
// normal mode
if mode_info.mode == InputMode::Normal && self.current_mode == InputMode::Locked
{
switch_to_input_mode(&self.standby_mode);
} else if mode_info.mode == InputMode::Normal
&& self.current_mode == self.standby_mode
{
switch_to_input_mode(&InputMode::Locked);
} else if mode_info.mode != InputMode::Locked
&& mode_info.mode != InputMode::Normal
{
self.standby_mode = mode_info.mode;
}
self.current_mode = mode_info.mode;
}

if self.mode_info != mode_info {
should_render = true;
}
Expand Down Expand Up @@ -244,7 +296,17 @@ impl ZellijPlugin for State {
};

let active_tab = self.tabs.iter().find(|t| t.active);
let first_line = first_line(&self.mode_info, active_tab, cols, separator);
let first_line = if self.supermode {
first_line_supermode(
&self.standby_mode,
&self.mode_info,
active_tab,
cols,
separator,
)
} else {
first_line(&self.mode_info, active_tab, cols, separator)
};
let second_line = self.second_line(cols);

let background = match self.mode_info.style.colors.theme_hue {
Expand Down Expand Up @@ -296,21 +358,16 @@ impl State {
} else if let Some(active_tab) = active_tab {
if active_tab.is_fullscreen_active {
match self.mode_info.mode {
InputMode::Normal => fullscreen_panes_to_hide(
&self.mode_info.style.colors,
active_tab.panes_to_hide,
),
InputMode::Locked => locked_fullscreen_panes_to_hide(
InputMode::Normal | InputMode::Locked => fullscreen_panes_to_hide(
&self.mode_info.style.colors,
active_tab.panes_to_hide,
),
_ => keybinds(&self.mode_info, &self.tip_name, cols),
}
} else if active_tab.are_floating_panes_visible {
match self.mode_info.mode {
InputMode::Normal => floating_panes_are_visible(&self.mode_info),
InputMode::Locked => {
locked_floating_panes_are_visible(&self.mode_info.style.colors)
InputMode::Normal | InputMode::Locked => {
floating_panes_are_visible(&self.mode_info)
},
_ => keybinds(&self.mode_info, &self.tip_name, cols),
}
Expand Down
Loading

0 comments on commit 27763d2

Please sign in to comment.