diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-03-30 20:34:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-30 20:34:12 +0200 |
| commit | 22ace8e54fbdadd08973854ae7178535a62065b1 (patch) | |
| tree | 0793eae0b4f0ae379b8cc73fda16ac4b3676e43d /zellij-utils | |
| parent | Error on socket paths that are too long (#4957) (diff) | |
| download | sl0ppij-22ace8e54fbdadd08973854ae7178535a62065b1.tar.gz sl0ppij-22ace8e54fbdadd08973854ae7178535a62065b1.tar.xz sl0ppij-22ace8e54fbdadd08973854ae7178535a62065b1.zip | |
Proper error when providing layout name with a tab (#4958)
* proper error when providing layout name with a tab
* rustfmt
Diffstat (limited to 'zellij-utils')
| -rw-r--r-- | zellij-utils/src/input/unit/layout_test.rs | 42 | ||||
| -rw-r--r-- | zellij-utils/src/kdl/kdl_layout_parser.rs | 18 |
2 files changed, 56 insertions, 4 deletions
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index 4ba33c12..52b71613 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -2341,7 +2341,7 @@ fn layout_node_with_multiple_tab_properties() { } #[test] -fn layout_node_with_tab_properties_and_explicit_tabs_errors() { +fn layout_node_with_name_and_explicit_tabs_errors() { let kdl_layout = r#" layout name="test" { tab { @@ -2355,7 +2355,45 @@ fn layout_node_with_tab_properties_and_explicit_tabs_errors() { assert!(layout.is_err()); let error_message = format!("{:?}", layout.unwrap_err()); assert!(error_message.contains( - "Tab properties on the layout node can only be used when there are no explicit tab nodes" + "name' property on the layout node is treated as a tab name and cannot be used when there are explicit tab nodes" + )); +} + +#[test] +fn layout_node_with_split_direction_and_explicit_tabs_errors() { + let kdl_layout = r#" + layout split_direction="vertical" { + tab { + pane + } + } + "#; + + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None); + + assert!(layout.is_err()); + let error_message = format!("{:?}", layout.unwrap_err()); + assert!(error_message.contains( + "split_direction' property on the layout node is treated as a tab property and cannot be used when there are explicit tab nodes" + )); +} + +#[test] +fn layout_node_with_hide_floating_panes_and_explicit_tabs_errors() { + let kdl_layout = r#" + layout hide_floating_panes=true { + tab { + pane + } + } + "#; + + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None); + + assert!(layout.is_err()); + let error_message = format!("{:?}", layout.unwrap_err()); + assert!(error_message.contains( + "hide_floating_panes' property on the layout node is treated as a tab property and cannot be used when there are explicit tab nodes" )); } diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs index ff7fcfe3..579a4b14 100644 --- a/zellij-utils/src/kdl/kdl_layout_parser.rs +++ b/zellij-utils/src/kdl/kdl_layout_parser.rs @@ -2505,9 +2505,23 @@ impl<'a> KdlLayoutParser<'a> { let layout_has_hide_floating = kdl_get_bool_property_or_child_value!(layout_node, "hide_floating_panes").is_some(); - if layout_has_tab_name || layout_has_split_direction || layout_has_hide_floating { + if layout_has_tab_name { return Err(ConfigError::new_layout_kdl_error( - "Tab properties on the layout node can only be used when there are no explicit tab nodes".into(), + "The 'name' property on the layout node is treated as a tab name and cannot be used when there are explicit tab nodes. To name individual tabs, use: tab name=\"my-tab\" { ... }".into(), + layout_node.span().offset(), + layout_node.span().len(), + )); + } + if layout_has_split_direction { + return Err(ConfigError::new_layout_kdl_error( + "The 'split_direction' property on the layout node is treated as a tab property and cannot be used when there are explicit tab nodes. To set split direction, place it on individual tab nodes: tab split_direction=\"vertical\" { ... }".into(), + layout_node.span().offset(), + layout_node.span().len(), + )); + } + if layout_has_hide_floating { + return Err(ConfigError::new_layout_kdl_error( + "The 'hide_floating_panes' property on the layout node is treated as a tab property and cannot be used when there are explicit tab nodes. To hide floating panes, place it on individual tab nodes: tab hide_floating_panes=true { ... }".into(), layout_node.span().offset(), layout_node.span().len(), )); |
