summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-28 22:08:01 +0100
committerGitHub <noreply@github.com>2023-02-28 22:08:01 +0100
commitea2d9ced6207acd2f401f6d95ac66565cc06d4a9 (patch)
tree8d15cfaeafcb57f849be431e49c85d707d273e8b /zellij-utils/src
parent6a8cf847da8bf1e56f4f713f38231aa9c925230e (diff)
feat(layouts): exact panes constraint (#2206)
* style(fmt): remove warnings * fix(swap-layouts): introduce exact panes constraint * fix(swap-layouts): improve floating pane swap layout ux * style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src')
-rw-r--r--zellij-utils/src/input/layout.rs1
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs49
-rw-r--r--zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-2.snap142
3 files changed, 168 insertions, 24 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index d6f5a2f7d..915c348a8 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -252,6 +252,7 @@ impl fmt::Display for RunPluginLocation {
pub enum LayoutConstraint {
MaxPanes(usize),
MinPanes(usize),
+ ExactPanes(usize),
NoConstraint,
}
diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs
index cf6afaf70..ee6c00399 100644
--- a/zellij-utils/src/kdl/kdl_layout_parser.rs
+++ b/zellij-utils/src/kdl/kdl_layout_parser.rs
@@ -119,6 +119,7 @@ impl<'a> KdlLayoutParser<'a> {
|| property_name == "children"
|| property_name == "max_panes"
|| property_name == "min_panes"
+ || property_name == "exact_panes"
}
fn assert_legal_node_name(&self, name: &str, kdl_node: &KdlNode) -> Result<(), ConfigError> {
if name.contains(char::is_whitespace) {
@@ -1747,6 +1748,12 @@ impl<'a> KdlLayoutParser<'a> {
tab_template_kdl_node,
)?;
swap_tiled_layout.insert(layout_constraint, layout);
+ } else {
+ return Err(ConfigError::new_layout_kdl_error(
+ format!("Unknown layout node: '{}'", layout_node_name),
+ layout.span().offset(),
+ layout.span().len(),
+ ));
}
}
swap_tiled_layouts.push((swap_tiled_layout, swap_layout_name));
@@ -1787,6 +1794,12 @@ impl<'a> KdlLayoutParser<'a> {
tab_template_kdl_node,
)?;
swap_floating_layout.insert(layout_constraint, layout);
+ } else {
+ return Err(ConfigError::new_layout_kdl_error(
+ format!("Unknown layout node: '{}'", layout_node_name),
+ layout.span().offset(),
+ layout.span().len(),
+ ));
}
}
swap_floating_layouts.push((swap_floating_layout, swap_layout_name));
@@ -1814,17 +1827,41 @@ impl<'a> KdlLayoutParser<'a> {
layout_node
));
};
+ if let Some(exact_panes) =
+ kdl_get_string_property_or_child_value!(layout_node, "exact_panes")
+ {
+ return Err(kdl_parsing_error!(
+ format!(
+ "exact_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")",
+ exact_panes,
+ ),
+ layout_node
+ ));
+ };
let max_panes = kdl_get_int_property_or_child_value!(layout_node, "max_panes");
let min_panes = kdl_get_int_property_or_child_value!(layout_node, "min_panes");
- match (min_panes, max_panes) {
- (Some(_min_panes), Some(_max_panes)) => Err(kdl_parsing_error!(
+ let exact_panes = kdl_get_int_property_or_child_value!(layout_node, "exact_panes");
+ let mut constraint_count = 0;
+ let mut constraint = None;
+ if let Some(max_panes) = max_panes {
+ constraint_count += 1;
+ constraint = Some(LayoutConstraint::MaxPanes(max_panes as usize));
+ }
+ if let Some(min_panes) = min_panes {
+ constraint_count += 1;
+ constraint = Some(LayoutConstraint::MinPanes(min_panes as usize));
+ }
+ if let Some(exact_panes) = exact_panes {
+ constraint_count += 1;
+ constraint = Some(LayoutConstraint::ExactPanes(exact_panes as usize));
+ }
+ if constraint_count > 1 {
+ return Err(kdl_parsing_error!(
format!("cannot have more than one constraint (eg. max_panes + min_panes)'"),
layout_node
- )),
- (Some(min_panes), None) => Ok(LayoutConstraint::MinPanes(min_panes as usize)),
- (None, Some(max_panes)) => Ok(LayoutConstraint::MaxPanes(max_panes as usize)),
- _ => Ok(LayoutConstraint::NoConstraint),
+ ));
}
+ Ok(constraint.unwrap_or(LayoutConstraint::NoConstraint))
}
fn populate_one_swap_tiled_layout(
&self,
diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-2.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-2.snap
index b87b9344c..f53ecc5ef 100644
--- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-2.snap
+++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-2.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/setup.rs
-assertion_line: 601
+assertion_line: 622
expression: "format!(\"{:#?}\", layout)"
---
Layout {
@@ -1213,8 +1213,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 1,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1238,8 +1238,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 2,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1263,8 +1263,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 3,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1288,8 +1288,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 4,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1313,7 +1313,7 @@ Layout {
),
),
x: Some(
- Fixed(
+ Percent(
5,
),
),
@@ -1338,8 +1338,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 6,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1363,8 +1363,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 7,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1388,8 +1388,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 8,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1413,8 +1413,8 @@ Layout {
),
),
x: Some(
- Fixed(
- 9,
+ Percent(
+ 5,
),
),
y: Some(
@@ -1596,6 +1596,112 @@ Layout {
focus: None,
},
],
+ MaxPanes(
+ 4,
+ ): [
+ FloatingPaneLayout {
+ name: None,
+ height: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ width: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ x: Some(
+ Percent(
+ 1,
+ ),
+ ),
+ y: Some(
+ Percent(
+ 55,
+ ),
+ ),
+ run: None,
+ focus: None,
+ },
+ FloatingPaneLayout {
+ name: None,
+ height: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ width: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ x: Some(
+ Percent(
+ 50,
+ ),
+ ),
+ y: Some(
+ Percent(
+ 55,
+ ),
+ ),
+ run: None,
+ focus: Some(
+ true,
+ ),
+ },
+ FloatingPaneLayout {
+ name: None,
+ height: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ width: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ x: Some(
+ Percent(
+ 1,
+ ),
+ ),
+ y: Some(
+ Percent(
+ 1,
+ ),
+ ),
+ run: None,
+ focus: None,
+ },
+ FloatingPaneLayout {
+ name: None,
+ height: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ width: Some(
+ Percent(
+ 45,
+ ),
+ ),
+ x: Some(
+ Percent(
+ 50,
+ ),
+ ),
+ y: Some(
+ Percent(
+ 1,
+ ),
+ ),
+ run: None,
+ focus: None,
+ },
+ ],
},
Some(
"spread",