aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-10-14 17:44:23 +0200
committerGitHub <noreply@github.com>2022-10-14 17:44:23 +0200
commitefceb562dec562babd90c711b30a5471e026fd3d (patch)
tree0d98a00319023c1f9724fc39cff018513413c6ee /zellij-utils/src/input
parentdocs(changelog): global cwd (diff)
downloadsl0ppij-efceb562dec562babd90c711b30a5471e026fd3d.tar.gz
sl0ppij-efceb562dec562babd90c711b30a5471e026fd3d.tar.xz
sl0ppij-efceb562dec562babd90c711b30a5471e026fd3d.zip
feat(layouts): edit panes (#1799)
* feat(layouts): edit panes * style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src/input')
-rw-r--r--zellij-utils/src/input/layout.rs14
-rw-r--r--zellij-utils/src/input/unit/layout_test.rs32
-rw-r--r--zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap37
-rw-r--r--zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap37
4 files changed, 120 insertions, 0 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index 8299c0bc..8e317a8e 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -62,11 +62,15 @@ pub enum Run {
Plugin(RunPlugin),
#[serde(rename = "command")]
Command(RunCommand),
+ EditFile(PathBuf, Option<usize>), // TODO: merge this with TerminalAction::OpenFile
Cwd(PathBuf),
}
impl Run {
pub fn merge(base: &Option<Run>, other: &Option<Run>) -> Option<Run> {
+ // This method is necessary to merge between pane_templates and their consumers
+ // TODO: reconsider the way we parse command/edit/plugin pane_templates from layouts to prevent this
+ // madness
// TODO: handle Plugin variants once there's a need
match (base, other) {
(Some(Run::Command(base_run_command)), Some(Run::Command(other_run_command))) => {
@@ -91,6 +95,16 @@ impl Run {
}
Some(Run::Command(merged))
},
+ (
+ Some(Run::Command(base_run_command)),
+ Some(Run::EditFile(file_to_edit, line_number)),
+ ) => match &base_run_command.cwd {
+ Some(cwd) => Some(Run::EditFile(cwd.join(&file_to_edit), *line_number)),
+ None => Some(Run::EditFile(file_to_edit.clone(), *line_number)),
+ },
+ (Some(Run::Cwd(cwd)), Some(Run::EditFile(file_to_edit, line_number))) => {
+ Some(Run::EditFile(cwd.join(&file_to_edit), *line_number))
+ },
(Some(_base), Some(other)) => Some(other.clone()),
(Some(base), _) => Some(base.clone()),
(None, Some(other)) => Some(other.clone()),
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs
index 82a221e2..6155024b 100644
--- a/zellij-utils/src/input/unit/layout_test.rs
+++ b/zellij-utils/src/input/unit/layout_test.rs
@@ -1283,6 +1283,38 @@ fn pane_template_with_bare_propagated_to_its_consumer_command_with_cwd() {
}
#[test]
+fn pane_template_with_bare_propagated_to_its_consumer_edit() {
+ let kdl_layout = r#"
+ layout {
+ cwd "/tmp"
+ pane_template name="tail" {
+ cwd "foo"
+ }
+ tail edit="bar"
+ // pane should have /tmp/foo/bar with the edit file variant
+ }
+ "#;
+ let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap();
+ assert_snapshot!(format!("{:#?}", layout));
+}
+
+#[test]
+fn pane_template_with_command_propagated_to_its_consumer_edit() {
+ let kdl_layout = r#"
+ layout {
+ cwd "/tmp"
+ pane_template name="tail" command="not-vim" {
+ cwd "foo"
+ }
+ tail edit="bar"
+ // pane should have /tmp/foo/bar with the edit file variant
+ }
+ "#;
+ let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap();
+ assert_snapshot!(format!("{:#?}", layout));
+}
+
+#[test]
fn global_cwd_given_to_panes_without_cwd() {
let kdl_layout = r#"
layout {
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap
new file mode 100644
index 00000000..32bc6880
--- /dev/null
+++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap
@@ -0,0 +1,37 @@
+---
+source: zellij-utils/src/input/./unit/layout_test.rs
+assertion_line: 1298
+expression: "format!(\"{:#?}\", layout)"
+---
+Layout {
+ tabs: [],
+ focused_tab_index: None,
+ template: Some(
+ PaneLayout {
+ children_split_direction: Horizontal,
+ name: None,
+ children: [
+ PaneLayout {
+ children_split_direction: Horizontal,
+ name: None,
+ children: [],
+ split_size: None,
+ run: Some(
+ EditFile(
+ "/tmp/foo/bar",
+ None,
+ ),
+ ),
+ borderless: false,
+ focus: None,
+ external_children_index: None,
+ },
+ ],
+ split_size: None,
+ run: None,
+ borderless: false,
+ focus: None,
+ external_children_index: None,
+ },
+ ),
+}
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap
new file mode 100644
index 00000000..f5f50be1
--- /dev/null
+++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap
@@ -0,0 +1,37 @@
+---
+source: zellij-utils/src/input/./unit/layout_test.rs
+assertion_line: 1314
+expression: "format!(\"{:#?}\", layout)"
+---
+Layout {
+ tabs: [],
+ focused_tab_index: None,
+ template: Some(
+ PaneLayout {
+ children_split_direction: Horizontal,
+ name: None,
+ children: [
+ PaneLayout {
+ children_split_direction: Horizontal,
+ name: None,
+ children: [],
+ split_size: None,
+ run: Some(
+ EditFile(
+ "/tmp/foo/bar",
+ None,
+ ),
+ ),
+ borderless: false,
+ focus: None,
+ external_children_index: None,
+ },
+ ],
+ split_size: None,
+ run: None,
+ borderless: false,
+ focus: None,
+ external_children_index: None,
+ },
+ ),
+}