From bbe2583904a7d4246400b75cc78f60047752f4b8 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 21 Sep 2021 16:39:37 +0200 Subject: 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 --- zellij-utils/src/input/layout.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'zellij-utils/src/input/layout.rs') 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 = 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 { + 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"] -- cgit v1.2.3