Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(ui): status bar redesign #3475

Merged
merged 14 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions default-plugins/status-bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rand = "0.8.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0.30"
unicode-width = "0.1.8"
zellij-tile = { path = "../../zellij-tile" }
zellij-tile-utils = { path = "../../zellij-tile-utils" }

Expand Down
47 changes: 40 additions & 7 deletions default-plugins/status-bar/src/first_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ use crate::{
};
use crate::{ColoredElements, LinePart};

struct KeyShortcut {
mode: KeyMode,
action: KeyAction,
key: Option<KeyWithModifier>,
#[derive(Debug)]
pub struct KeyShortcut {
pub mode: KeyMode,
pub action: KeyAction,
pub key: Option<KeyWithModifier>,
}

#[derive(PartialEq)]
enum KeyAction {
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum KeyAction {
Unlock,
Lock,
Pane,
Tab,
Expand All @@ -27,7 +29,8 @@ enum KeyAction {
Tmux,
}

enum KeyMode {
#[derive(Debug, Copy, Clone)]
pub enum KeyMode {
Unselected,
UnselectedAlternate,
Selected,
Expand All @@ -42,6 +45,7 @@ impl KeyShortcut {
pub fn full_text(&self) -> String {
match self.action {
KeyAction::Lock => String::from("LOCK"),
KeyAction::Unlock => String::from("UNLOCK"),
KeyAction::Pane => String::from("PANE"),
KeyAction::Tab => String::from("TAB"),
KeyAction::Resize => String::from("RESIZE"),
Expand Down Expand Up @@ -82,6 +86,35 @@ impl KeyShortcut {
};
format!("{}", key)
}
pub fn get_key(&self) -> Option<KeyWithModifier> {
self.key.clone()
}
pub fn get_mode(&self) -> KeyMode {
self.mode
}
pub fn get_action(&self) -> KeyAction {
self.action
}
pub fn is_selected(&self) -> bool {
match self.mode {
KeyMode::Selected => true,
_ => false,
}
}
pub fn short_text(&self) -> String {
match self.action {
KeyAction::Lock => String::from("Lo"),
KeyAction::Unlock => String::from("Un"),
KeyAction::Pane => String::from("Pa"),
KeyAction::Tab => String::from("Ta"),
KeyAction::Resize => String::from("Re"),
KeyAction::Search => String::from("Se"),
KeyAction::Quit => String::from("Qu"),
KeyAction::Session => String::from("Se"),
KeyAction::Move => String::from("Mo"),
KeyAction::Tmux => String::from("Tm"),
}
}
}

/// Generate long mode shortcut tile.
Expand Down
30 changes: 25 additions & 5 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod first_line;
mod one_line_ui;
mod second_line;
mod tip;

Expand All @@ -15,6 +16,7 @@ use zellij_tile::prelude::*;
use zellij_tile_utils::{palette_match, style};

use first_line::first_line;
use one_line_ui::one_line_ui;
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,
Expand All @@ -35,6 +37,8 @@ struct State {
mode_info: ModeInfo,
text_copy_destination: Option<CopyDestination>,
display_system_clipboard_failure: bool,
classic_ui: bool,
base_mode_is_locked: bool,
}

register_plugin!(State);
Expand Down Expand Up @@ -177,9 +181,13 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
}

impl ZellijPlugin for State {
fn load(&mut self, _configuration: BTreeMap<String, String>) {
fn load(&mut self, configuration: BTreeMap<String, String>) {
// TODO: Should be able to choose whether to use the cache through config.
self.tip_name = get_cached_tip_name();
self.classic_ui = configuration
.get("classic")
.map(|c| c == "true")
.unwrap_or(false);
set_selectable(false);
subscribe(&[
EventType::ModeUpdate,
Expand All @@ -198,6 +206,7 @@ impl ZellijPlugin for State {
should_render = true;
}
self.mode_info = mode_info;
self.base_mode_is_locked = self.mode_info.base_mode == Some(InputMode::Locked);
},
Event::TabUpdate(tabs) => {
if self.tabs != tabs {
Expand Down Expand Up @@ -244,6 +253,21 @@ impl ZellijPlugin for State {
""
};

if rows == 1 && !self.classic_ui {
let active_tab = self.tabs.iter().find(|t| t.active);
print!(
"{}",
one_line_ui(
&self.mode_info,
active_tab,
cols,
separator,
self.base_mode_is_locked
)
);
return;
}

let active_tab = self.tabs.iter().find(|t| t.active);
let first_line = first_line(&self.mode_info, active_tab, cols, separator);
let second_line = self.second_line(cols);
Expand Down Expand Up @@ -418,10 +442,6 @@ pub fn style_key_with_modifier(

let common_modifiers = get_common_modifiers(keyvec.iter().collect());

// let modifier_str = match get_common_modifier(keyvec.iter().collect()) {
// Some(modifier) => modifier,
// None => "".to_string(),
// };
let no_common_modifier = common_modifiers.is_empty();
let modifier_str = common_modifiers
.iter()
Expand Down
Loading
Loading