summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-10-14 13:22:32 +0200
committerAram Drevekenin <aram@poor.dev>2022-10-14 13:22:32 +0200
commit8cbc78f34d44a965b940cfbc931040389671d1b4 (patch)
treefa85e65655909167cbd998b564e0a91353c3f5a3
parentd860fe22c39251ef14d1485bc649c7425769c991 (diff)
fix(layouts): error on mixed cwd and pane childrenlayout_global_cwd
-rw-r--r--zellij-utils/src/input/unit/layout_test.rs14
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs7
2 files changed, 20 insertions, 1 deletions
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs
index 88939e167..82a221e2e 100644
--- a/zellij-utils/src/input/unit/layout_test.rs
+++ b/zellij-utils/src/input/unit/layout_test.rs
@@ -1099,6 +1099,20 @@ fn error_on_mixed_command_and_child_panes() {
}
#[test]
+fn error_on_mixed_cwd_and_child_panes() {
+ let kdl_layout = r#"
+ layout {
+ pane cwd="/tmp" {
+ pane
+ pane
+ }
+ }
+ "#;
+ let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None);
+ assert!(layout.is_err(), "error provided");
+}
+
+#[test]
fn error_on_bare_args_without_command() {
let kdl_layout = r#"
layout {
diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs
index b8f60d8a0..d7df58890 100644
--- a/zellij-utils/src/kdl/kdl_layout_parser.rs
+++ b/zellij-utils/src/kdl/kdl_layout_parser.rs
@@ -622,6 +622,8 @@ impl<'a> KdlLayoutParser<'a> {
kdl_get_bool_property_or_child_value_with_error!(kdl_node, "borderless").is_some();
let has_focus_prop =
kdl_get_bool_property_or_child_value_with_error!(kdl_node, "focus").is_some();
+ let has_cwd_prop =
+ kdl_get_string_property_or_child_value_with_error!(kdl_node, "cwd").is_some();
let has_non_cwd_run_prop = self
.parse_command_or_plugin_block(kdl_node)?
.map(|r| match r {
@@ -631,7 +633,7 @@ impl<'a> KdlLayoutParser<'a> {
.unwrap_or(false);
let has_nested_nodes_or_children_block = self.has_child_panes_tabs_or_templates(kdl_node);
if has_nested_nodes_or_children_block
- && (has_borderless_prop || has_focus_prop || has_non_cwd_run_prop)
+ && (has_borderless_prop || has_focus_prop || has_non_cwd_run_prop || has_cwd_prop)
{
let mut offending_nodes = vec![];
if has_borderless_prop {
@@ -643,6 +645,9 @@ impl<'a> KdlLayoutParser<'a> {
if has_non_cwd_run_prop {
offending_nodes.push("command/plugin");
}
+ if has_cwd_prop {
+ offending_nodes.push("cwd");
+ }
Err(ConfigError::new_kdl_error(
format!(
"Cannot have both properties ({}) and nested children",