From 6ea5c3666fa2f38742da115d5fe5beef30eccc2f Mon Sep 17 00:00:00 2001 From: Marcel Baur Date: Thu, 30 Mar 2023 13:33:39 +0200 Subject: [PATCH] Add option to hide session name in tab-bar (deriving from #2172) (#2301) * feat(tab-bar): add option to hide prefix (#2172) * feat(tab-bar): only hide session_name * fix(snapshots): update snapshots with new config-var naming --------- Co-authored-by: Marcel Baur --- default-plugins/tab-bar/src/line.rs | 6 +++++- default-plugins/tab-bar/src/main.rs | 1 + zellij-client/src/lib.rs | 1 + ..._server__screen__screen_tests__send_cli_rename_tab.snap | 3 ++- ...er__screen__screen_tests__send_cli_undo_rename_tab.snap | 3 ++- zellij-utils/src/data.rs | 1 + zellij-utils/src/input/config.rs | 2 ++ zellij-utils/src/input/theme.rs | 2 ++ zellij-utils/src/kdl/mod.rs | 7 ++++++- ...__setup_test__default_config_with_no_cli_arguments.snap | 2 +- ...tup_test__layout_env_vars_override_config_env_vars.snap | 2 +- ...tup_test__layout_keybinds_override_config_keybinds.snap | 2 +- ...setup_test__layout_plugins_override_config_plugins.snap | 2 +- ...__setup_test__layout_themes_override_config_themes.snap | 2 +- ..._test__layout_ui_config_overrides_config_ui_config.snap | 2 +- 15 files changed, 28 insertions(+), 10 deletions(-) diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index cb24873a9..668507a01 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -223,6 +223,7 @@ pub fn tab_line( cols: usize, palette: Palette, capabilities: PluginCapabilities, + hide_session_name: bool, ) -> Vec { let mut tabs_after_active = all_tabs.split_off(active_tab_index); let mut tabs_before_active = all_tabs; @@ -231,7 +232,10 @@ pub fn tab_line( } else { tabs_before_active.pop().unwrap() }; - let mut prefix = tab_line_prefix(session_name, palette, cols); + let mut prefix = match hide_session_name { + true => tab_line_prefix(None, palette, cols), + false => tab_line_prefix(session_name, palette, cols), + }; let prefix_len = get_current_title_len(&prefix); // if active tab alone won't fit in cols, don't draw any tabs diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index 6f0456a8f..2df6a13df 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -120,6 +120,7 @@ impl ZellijPlugin for State { cols.saturating_sub(1), self.mode_info.style.colors, self.mode_info.capabilities, + self.mode_info.style.hide_session_name, ); let mut s = String::new(); let mut len_cnt = 0; diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 68bc45e9e..fb58db275 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -167,6 +167,7 @@ pub fn start_client( style: Style { colors: palette, rounded_corners: config.ui.pane_frames.rounded_corners, + hide_session_name: config.ui.pane_frames.hide_session_name, }, keybinds: config.keybinds.clone(), }; diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap index 0cbb23d5c..2423ce987 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap @@ -1,6 +1,5 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2629 expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" --- [ @@ -136,6 +135,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ), }, rounded_corners: false, + hide_session_name: false, }, capabilities: PluginCapabilities { arrow_fonts: false, @@ -292,6 +292,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ), }, rounded_corners: false, + hide_session_name: false, }, capabilities: PluginCapabilities { arrow_fonts: false, diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap index 69a6bcd91..0b777a1ef 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap @@ -1,6 +1,5 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2672 expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" --- [ @@ -136,6 +135,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ), }, rounded_corners: false, + hide_session_name: false, }, capabilities: PluginCapabilities { arrow_fonts: false, @@ -292,6 +292,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" ), }, rounded_corners: false, + hide_session_name: false, }, capabilities: PluginCapabilities { arrow_fonts: false, diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index f5c4828e3..6da375f51 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -643,6 +643,7 @@ pub struct Palette { pub struct Style { pub colors: Palette, pub rounded_corners: bool, + pub hide_session_name: bool, } // FIXME: Poor devs hashtable since HashTable can't derive `Default`... diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index 5cdc509ff..9d0c6da39 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -639,6 +639,7 @@ mod config_test { ui { pane_frames { rounded_corners true + hide_session_name true } } "#; @@ -646,6 +647,7 @@ mod config_test { let expected_ui_config = UiConfig { pane_frames: FrameConfig { rounded_corners: true, + hide_session_name: true, }, }; assert_eq!(config.ui, expected_ui_config, "Ui config defined in config"); diff --git a/zellij-utils/src/input/theme.rs b/zellij-utils/src/input/theme.rs index c76deb31f..bf0edf232 100644 --- a/zellij-utils/src/input/theme.rs +++ b/zellij-utils/src/input/theme.rs @@ -25,12 +25,14 @@ impl UiConfig { #[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)] pub struct FrameConfig { pub rounded_corners: bool, + pub hide_session_name: bool, } impl FrameConfig { pub fn merge(&self, other: FrameConfig) -> Self { let mut merged = self.clone(); merged.rounded_corners = other.rounded_corners; + merged.hide_session_name = other.hide_session_name; merged } } diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index 1bd1356c1..fa11077c0 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1701,7 +1701,12 @@ impl UiConfig { let rounded_corners = kdl_children_property_first_arg_as_bool!(pane_frames, "rounded_corners") .unwrap_or(false); - let frame_config = FrameConfig { rounded_corners }; + let hide_session_name = + kdl_get_child_entry_bool_value!(pane_frames, "hide_session_name").unwrap_or(false); + let frame_config = FrameConfig { + rounded_corners, + hide_session_name, + }; ui_config.pane_frames = frame_config; } Ok(ui_config) diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap index 6ba666801..a51321f89 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 621 expression: "format!(\"{:#?}\", config)" --- Config { @@ -3604,6 +3603,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: false, + hide_session_name: false, }, }, env: {}, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap index 97a16c77b..226385df8 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 679 expression: "format!(\"{:#?}\", config)" --- Config { @@ -3604,6 +3603,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: false, + hide_session_name: false, }, }, env: { diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap index e8d8bccbc..55574997d 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 696 expression: "format!(\"{:#?}\", config)" --- Config { @@ -144,6 +143,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: false, + hide_session_name: false, }, }, env: {}, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap index 2b07b2f9b..772eb5266 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 707 expression: "format!(\"{:#?}\", config)" --- Config { @@ -3618,6 +3617,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: false, + hide_session_name: false, }, }, env: {}, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap index 13e440e0d..e4532bbe3 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 721 expression: "format!(\"{:#?}\", config)" --- Config { @@ -3908,6 +3907,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: false, + hide_session_name: false, }, }, env: {}, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap index 072f21828..001041fce 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap @@ -1,6 +1,5 @@ --- source: zellij-utils/src/setup.rs -assertion_line: 693 expression: "format!(\"{:#?}\", config)" --- Config { @@ -3604,6 +3603,7 @@ Config { ui: UiConfig { pane_frames: FrameConfig { rounded_corners: true, + hide_session_name: false, }, }, env: {},