diff options
author | Kunal Mohan <44079328+kunalmohan@users.noreply.github.com> | 2021-12-09 23:30:40 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 23:30:40 +0530 |
commit | c75bcbd9370249f23031edcd69f6724805c1e034 (patch) | |
tree | a45dab48eb4a0eea8f008db2278ea68c8166b044 /zellij-utils/src | |
parent | 368c852e57f3aa0596ef0459d6e9cc41b314cf65 (diff) |
Feature: Add pane names (#928)
* Read pane name from layout
* Update pane name at runtime
* Fix tests
* prefer and render pane name over pane title
* fix clippy errors
* fix after rebase
Diffstat (limited to 'zellij-utils/src')
-rw-r--r-- | zellij-utils/src/errors.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/actions.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/keybinds.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 11 | ||||
-rw-r--r-- | zellij-utils/src/input/mod.rs | 2 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/layout_test.rs | 58 | ||||
-rw-r--r-- | zellij-utils/src/ipc.rs | 2 |
7 files changed, 75 insertions, 1 deletions
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index f8b8def98..a546e6cc7 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -251,6 +251,7 @@ pub enum ScreenContext { SetFixedHeight, SetFixedWidth, ClosePane, + UpdatePaneName, NewTab, SwitchTabNext, SwitchTabPrev, diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index c84ad285e..d29799fbb 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -83,6 +83,7 @@ pub enum Action { NewPane(Option<Direction>), /// Close the focus pane. CloseFocus, + PaneNameInput(Vec<u8>), /// Create a new tab, optionally with a specified tab layout. NewTab(Option<TabLayout>), /// Do nothing. diff --git a/zellij-utils/src/input/keybinds.rs b/zellij-utils/src/input/keybinds.rs index fcc2e4a87..47b7fc3e0 100644 --- a/zellij-utils/src/input/keybinds.rs +++ b/zellij-utils/src/input/keybinds.rs @@ -209,6 +209,7 @@ impl Keybinds { mode_keybind_or_action(Action::Write(raw_bytes)) } InputMode::RenameTab => mode_keybind_or_action(Action::TabNameInput(raw_bytes)), + InputMode::RenamePane => mode_keybind_or_action(Action::PaneNameInput(raw_bytes)), _ => mode_keybind_or_action(Action::NoOp), } } diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 29b8de00f..9fa6709c2 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -133,6 +133,8 @@ impl fmt::Display for RunPluginLocation { pub struct Layout { pub direction: Direction, #[serde(default)] + pub pane_name: Option<String>, + #[serde(default)] pub parts: Vec<Layout>, pub split_size: Option<SplitSize>, pub run: Option<Run>, @@ -411,6 +413,8 @@ fn default_as_some_true() -> Option<bool> { pub struct LayoutTemplate { pub direction: Direction, #[serde(default)] + pub pane_name: Option<String>, + #[serde(default)] pub borderless: bool, #[serde(default)] pub parts: Vec<LayoutTemplate>, @@ -454,6 +458,7 @@ impl LayoutTemplate { pub struct TabLayout { #[serde(default)] pub direction: Direction, + pub pane_name: Option<String>, #[serde(default)] pub borderless: bool, #[serde(default)] @@ -703,6 +708,7 @@ impl TryFrom<TabLayout> for Layout { fn try_from(tab: TabLayout) -> Result<Self, Self::Error> { Ok(Layout { direction: tab.direction, + pane_name: tab.pane_name, borderless: tab.borderless, parts: Self::from_vec_tab_layout(tab.parts)?, split_size: tab.split_size, @@ -715,6 +721,7 @@ impl From<TabLayout> for LayoutTemplate { fn from(tab: TabLayout) -> Self { Self { direction: tab.direction, + pane_name: tab.pane_name, borderless: tab.borderless, parts: Self::from_vec_tab_layout(tab.parts), body: false, @@ -730,6 +737,7 @@ impl TryFrom<LayoutTemplate> for Layout { fn try_from(template: LayoutTemplate) -> Result<Self, Self::Error> { Ok(Layout { direction: template.direction, + pane_name: template.pane_name, borderless: template.borderless, parts: Self::from_vec_template_layout(template.parts)?, split_size: template.split_size, @@ -752,6 +760,7 @@ impl Default for TabLayout { split_size: None, run: None, name: String::new(), + pane_name: None, } } } @@ -760,10 +769,12 @@ impl Default for LayoutTemplate { fn default() -> Self { Self { direction: Direction::Horizontal, + pane_name: None, body: false, borderless: false, parts: vec![LayoutTemplate { direction: Direction::Horizontal, + pane_name: None, body: true, borderless: false, split_size: None, diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index a10ffa2cd..34572ba79 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -40,6 +40,7 @@ pub fn get_mode_info( ("x".to_string(), "Close".to_string()), ("f".to_string(), "Fullscreen".to_string()), ("z".to_string(), "Frames".to_string()), + ("c".to_string(), "Rename".to_string()), ], InputMode::Tab => vec![ ("←↓↑→".to_string(), "Move focus".to_string()), @@ -55,6 +56,7 @@ pub fn get_mode_info( ("u/d".to_string(), "Scroll Half Page".to_string()), ], InputMode::RenameTab => vec![("Enter".to_string(), "when done".to_string())], + InputMode::RenamePane => vec![("Enter".to_string(), "when done".to_string())], InputMode::Session => vec![("d".to_string(), "Detach".to_string())], }; diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index 2ec66a2a0..aec34c458 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -40,10 +40,12 @@ fn default_layout_merged_correctly() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: true, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(1)), run: Some(Run::Plugin(RunPlugin { @@ -54,6 +56,7 @@ fn default_layout_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -61,6 +64,7 @@ fn default_layout_merged_correctly() { Layout { direction: Direction::Vertical, borderless: true, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(2)), run: Some(Run::Plugin(RunPlugin { @@ -84,10 +88,12 @@ fn default_layout_new_tab_correct() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: true, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(1)), run: Some(Run::Plugin(RunPlugin { @@ -98,6 +104,7 @@ fn default_layout_new_tab_correct() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -105,6 +112,7 @@ fn default_layout_new_tab_correct() { Layout { direction: Direction::Vertical, borderless: true, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(2)), run: Some(Run::Plugin(RunPlugin { @@ -168,13 +176,16 @@ fn three_panes_with_tab_merged_correctly() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -182,10 +193,12 @@ fn three_panes_with_tab_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -193,6 +206,7 @@ fn three_panes_with_tab_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -220,9 +234,11 @@ fn three_panes_with_tab_new_tab_is_correct() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -260,10 +276,12 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(1)), run: Some(Run::Plugin(RunPlugin { @@ -274,10 +292,12 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -285,10 +305,12 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -296,6 +318,7 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -311,6 +334,7 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(2)), run: Some(Run::Plugin(RunPlugin { @@ -334,10 +358,12 @@ fn three_panes_with_tab_and_default_plugins_new_tab_is_correct() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(1)), run: Some(Run::Plugin(RunPlugin { @@ -348,6 +374,7 @@ fn three_panes_with_tab_and_default_plugins_new_tab_is_correct() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -355,6 +382,7 @@ fn three_panes_with_tab_and_default_plugins_new_tab_is_correct() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Fixed(2)), run: Some(Run::Plugin(RunPlugin { @@ -396,14 +424,17 @@ fn deeply_nested_tab_merged_correctly() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(21.0)), run: None, @@ -411,10 +442,12 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(22.0)), run: None, @@ -422,10 +455,12 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(23.0)), run: None, @@ -433,6 +468,7 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(24.0)), run: None, @@ -452,6 +488,7 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(15.0)), run: None, @@ -459,6 +496,7 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(15.0)), run: None, @@ -466,6 +504,7 @@ fn deeply_nested_tab_merged_correctly() { Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(15.0)), run: None, @@ -504,10 +543,12 @@ fn three_tabs_tab_one_merged_correctly() { let merged_layout = Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -515,6 +556,7 @@ fn three_tabs_tab_one_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -539,14 +581,17 @@ fn three_tabs_tab_two_merged_correctly() { let merged_layout = Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -554,6 +599,7 @@ fn three_tabs_tab_two_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -565,6 +611,7 @@ fn three_tabs_tab_two_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -589,14 +636,17 @@ fn three_tabs_tab_three_merged_correctly() { let merged_layout = Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![ Layout { direction: Direction::Vertical, borderless: false, + pane_name: None, parts: vec![], split_size: Some(SplitSize::Percent(50.0)), run: None, @@ -604,6 +654,7 @@ fn three_tabs_tab_three_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -615,6 +666,7 @@ fn three_tabs_tab_three_merged_correctly() { Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -650,9 +702,11 @@ fn no_tabs_merged_correctly() { let merged_layout = Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![Layout { direction: Direction::Horizontal, borderless: false, + pane_name: None, parts: vec![], split_size: None, run: None, @@ -699,6 +753,7 @@ fn no_layout_template_merged_correctly() { split_size: None, run: None, borderless: false, + pane_name: None, }, Layout { direction: Direction::Horizontal, @@ -706,15 +761,18 @@ fn no_layout_template_merged_correctly() { split_size: None, run: None, borderless: false, + pane_name: None, }, ], split_size: None, run: None, borderless: false, + pane_name: None, }], split_size: None, run: None, borderless: false, + pane_name: None, }; assert_eq!(merged_layout, tab_layout.try_into().unwrap()); diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs index b27a097a1..2716dd3cc 100644 --- a/zellij-utils/src/ipc.rs +++ b/zellij-utils/src/ipc.rs @@ -62,7 +62,7 @@ pub enum ClientToServerMsg { ClientAttributes, Box<CliArgs>, Box<Options>, - LayoutFromYaml, + Box<LayoutFromYaml>, Option<PluginsConfig>, ), AttachClient(ClientAttributes, Options), |