diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-09-21 16:39:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-21 16:39:37 +0200 |
commit | bbe2583904a7d4246400b75cc78f60047752f4b8 (patch) | |
tree | ce34cd778777256dd900888b5f92760137add553 /zellij-utils/src/input/layout.rs | |
parent | 71b600b8210b611c312ec6358795eb073d66eb4a (diff) |
feat(layout): specify only tab name in `tabs` section (#722)
Allow specifying only the tab name in the `tabs` section
- For example this is now possible:
```
tabs:
- name: first
parts:
- direction: Vertical
- direction: Vertical
- name: second
- name: third
```
For that the tab section defaults the direction to
`direction::Horizontal`
- Adds an error upon specifying a tab name inside the `parts` section
of the tab-layout
Diffstat (limited to 'zellij-utils/src/input/layout.rs')
-rw-r--r-- | zellij-utils/src/input/layout.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 98fdb0d12..9dc8cd47b 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -9,7 +9,10 @@ // If plugins should be able to depend on the layout system // then [`zellij-utils`] could be a proper place. use crate::{ - input::{command::RunCommand, config::ConfigError}, + input::{ + command::RunCommand, + config::{ConfigError, LayoutNameInTabError}, + }, pane_size::{Dimension, PaneGeom}, setup, }; @@ -106,7 +109,12 @@ impl LayoutFromYaml { let layout: Option<LayoutFromYaml> = serde_yaml::from_str(&layout)?; match layout { - Some(layout) => Ok(layout), + Some(layout) => { + for tab in layout.tabs.clone() { + tab.check()?; + } + Ok(layout) + } None => Ok(LayoutFromYaml::default()), } } @@ -220,6 +228,7 @@ impl LayoutTemplate { #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] #[serde(crate = "self::serde")] pub struct TabLayout { + #[serde(default)] pub direction: Direction, #[serde(default)] pub borderless: bool, @@ -231,6 +240,18 @@ pub struct TabLayout { pub name: String, } +impl TabLayout { + fn check(&self) -> Result<TabLayout, ConfigError> { + for part in self.parts.iter() { + part.check()?; + if !part.name.is_empty() { + return Err(ConfigError::LayoutNameInTab(LayoutNameInTabError)); + } + } + Ok(self.clone()) + } +} + impl Layout { pub fn total_terminal_panes(&self) -> usize { let mut total_panes = 0; @@ -467,6 +488,12 @@ impl Default for LayoutFromYaml { } } +impl Default for Direction { + fn default() -> Self { + Direction::Horizontal + } +} + // The unit test location. #[cfg(test)] #[path = "./unit/layout_test.rs"] |