Skip to content

Commit 27763d2

Browse files
authored
feat(ui): new status bar mode (zellij-org#2619)
* supermode prototype * fix integration tests * fix tests * style(fmt): rustfmt
1 parent 61f3789 commit 27763d2

12 files changed

+439
-173
lines changed

default-plugins/status-bar/src/first_line.rs

+333-34
Large diffs are not rendered by default.

default-plugins/status-bar/src/main.rs

+69-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use zellij_tile::prelude::actions::Action;
1313
use zellij_tile::prelude::*;
1414
use zellij_tile_utils::{palette_match, style};
1515

16-
use first_line::first_line;
16+
use first_line::{first_line, first_line_supermode};
1717
use second_line::{
18-
floating_panes_are_visible, fullscreen_panes_to_hide, keybinds,
19-
locked_floating_panes_are_visible, locked_fullscreen_panes_to_hide, system_clipboard_error,
18+
floating_panes_are_visible, fullscreen_panes_to_hide, keybinds, system_clipboard_error,
2019
text_copied_hint,
2120
};
2221
use tip::utils::get_cached_tip_name;
@@ -34,6 +33,10 @@ struct State {
3433
mode_info: ModeInfo,
3534
text_copy_destination: Option<CopyDestination>,
3635
display_system_clipboard_failure: bool,
36+
37+
supermode: bool,
38+
standby_mode: InputMode,
39+
current_mode: InputMode,
3740
}
3841

3942
register_plugin!(State);
@@ -60,6 +63,7 @@ impl Display for LinePart {
6063
#[derive(Clone, Copy)]
6164
pub struct ColoredElements {
6265
pub selected: SegmentStyle,
66+
pub selected_standby_shortcut: SegmentStyle,
6367
pub unselected: SegmentStyle,
6468
pub unselected_alternate: SegmentStyle,
6569
pub disabled: SegmentStyle,
@@ -109,6 +113,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
109113
styled_text: style!(background, palette.green).bold(),
110114
suffix_separator: style!(palette.green, background).bold(),
111115
},
116+
selected_standby_shortcut: SegmentStyle {
117+
prefix_separator: style!(background, palette.green),
118+
char_left_separator: style!(background, palette.green).bold(),
119+
char_shortcut: style!(palette.red, palette.green).bold(),
120+
char_right_separator: style!(background, palette.green).bold(),
121+
styled_text: style!(background, palette.green).bold(),
122+
suffix_separator: style!(palette.green, palette.fg).bold(),
123+
},
112124
unselected: SegmentStyle {
113125
prefix_separator: style!(background, palette.fg),
114126
char_left_separator: style!(background, palette.fg).bold(),
@@ -145,6 +157,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
145157
styled_text: style!(background, palette.green).bold(),
146158
suffix_separator: style!(palette.green, background).bold(),
147159
},
160+
selected_standby_shortcut: SegmentStyle {
161+
prefix_separator: style!(background, palette.green),
162+
char_left_separator: style!(background, palette.green).bold(),
163+
char_shortcut: style!(palette.red, palette.green).bold(),
164+
char_right_separator: style!(background, palette.green).bold(),
165+
styled_text: style!(background, palette.green).bold(),
166+
suffix_separator: style!(palette.green, palette.fg).bold(),
167+
},
148168
unselected: SegmentStyle {
149169
prefix_separator: style!(background, palette.fg),
150170
char_left_separator: style!(background, palette.fg).bold(),
@@ -187,12 +207,44 @@ impl ZellijPlugin for State {
187207
EventType::InputReceived,
188208
EventType::SystemClipboardFailure,
189209
]);
210+
self.supermode = false; // TODO: from config
211+
self.standby_mode = InputMode::Pane;
212+
if self.supermode {
213+
switch_to_input_mode(&InputMode::Locked); // supermode should start locked (TODO: only
214+
// once per app load, let's not do this on
215+
// each tab loading)
216+
}
190217
}
191218

192219
fn update(&mut self, event: Event) -> bool {
193220
let mut should_render = false;
194221
match event {
195222
Event::ModeUpdate(mode_info) => {
223+
if self.supermode {
224+
// supermode is a "sticky" mode that is not Normal or Locked
225+
// using this configuration, we default to Locked mode in order to avoid key
226+
// collisions with terminal applications
227+
// whenever the user switches away from locked mode, we make sure to place them
228+
// in the standby mode
229+
// whenever the user switches to a mode that is not locked or normal, we set
230+
// that mode as the standby mode
231+
// whenever the user switches away from the standby mode, we palce them in
232+
// normal mode
233+
if mode_info.mode == InputMode::Normal && self.current_mode == InputMode::Locked
234+
{
235+
switch_to_input_mode(&self.standby_mode);
236+
} else if mode_info.mode == InputMode::Normal
237+
&& self.current_mode == self.standby_mode
238+
{
239+
switch_to_input_mode(&InputMode::Locked);
240+
} else if mode_info.mode != InputMode::Locked
241+
&& mode_info.mode != InputMode::Normal
242+
{
243+
self.standby_mode = mode_info.mode;
244+
}
245+
self.current_mode = mode_info.mode;
246+
}
247+
196248
if self.mode_info != mode_info {
197249
should_render = true;
198250
}
@@ -244,7 +296,17 @@ impl ZellijPlugin for State {
244296
};
245297

246298
let active_tab = self.tabs.iter().find(|t| t.active);
247-
let first_line = first_line(&self.mode_info, active_tab, cols, separator);
299+
let first_line = if self.supermode {
300+
first_line_supermode(
301+
&self.standby_mode,
302+
&self.mode_info,
303+
active_tab,
304+
cols,
305+
separator,
306+
)
307+
} else {
308+
first_line(&self.mode_info, active_tab, cols, separator)
309+
};
248310
let second_line = self.second_line(cols);
249311

250312
let background = match self.mode_info.style.colors.theme_hue {
@@ -296,21 +358,16 @@ impl State {
296358
} else if let Some(active_tab) = active_tab {
297359
if active_tab.is_fullscreen_active {
298360
match self.mode_info.mode {
299-
InputMode::Normal => fullscreen_panes_to_hide(
300-
&self.mode_info.style.colors,
301-
active_tab.panes_to_hide,
302-
),
303-
InputMode::Locked => locked_fullscreen_panes_to_hide(
361+
InputMode::Normal | InputMode::Locked => fullscreen_panes_to_hide(
304362
&self.mode_info.style.colors,
305363
active_tab.panes_to_hide,
306364
),
307365
_ => keybinds(&self.mode_info, &self.tip_name, cols),
308366
}
309367
} else if active_tab.are_floating_panes_visible {
310368
match self.mode_info.mode {
311-
InputMode::Normal => floating_panes_are_visible(&self.mode_info),
312-
InputMode::Locked => {
313-
locked_floating_panes_are_visible(&self.mode_info.style.colors)
369+
InputMode::Normal | InputMode::Locked => {
370+
floating_panes_are_visible(&self.mode_info)
314371
},
315372
_ => keybinds(&self.mode_info, &self.tip_name, cols),
316373
}

0 commit comments

Comments
 (0)