diff options
| author | Aram Drevekenin <aram@poor.dev> | 2022-11-01 09:07:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-01 09:07:25 +0100 |
| commit | abc700fc4d10d61c969ad94fa520d7d9336dcf14 (patch) | |
| tree | a2e6318c4fe3951236cfa758befce8b95393a26e /zellij-utils/src | |
| parent | docs(changelog): status bar fix (diff) | |
| download | sl0ppij-abc700fc4d10d61c969ad94fa520d7d9336dcf14.tar.gz sl0ppij-abc700fc4d10d61c969ad94fa520d7d9336dcf14.tar.xz sl0ppij-abc700fc4d10d61c969ad94fa520d7d9336dcf14.zip | |
feat(command-panes): allow to start suspended (#1887)
* feat(command-panes): allow panes to start suspended
* style(fmt): remove unused code
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src')
33 files changed, 186 insertions, 52 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index f860f05f..baa53b9a 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -141,6 +141,10 @@ pub enum Sessions { /// Close the pane immediately when its command exits #[clap(short, long, value_parser, default_value("false"), takes_value(false))] close_on_exit: bool, + + /// Start the command suspended, only running after you first presses ENTER + #[clap(short, long, value_parser, default_value("false"), takes_value(false))] + start_suspended: bool, }, /// Edit file with default $EDITOR / $VISUAL #[clap(visible_alias = "e")] @@ -252,6 +256,16 @@ pub enum CliAction { requires("command") )] close_on_exit: bool, + /// Start the command suspended, only running it after the you first press ENTER + #[clap( + short, + long, + value_parser, + default_value("false"), + takes_value(false), + requires("command") + )] + start_suspended: bool, }, /// Open the specified file in a new zellij pane with your default EDITOR Edit { diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index f63390ad..189f3cd9 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -260,11 +260,13 @@ impl Action { floating, name, close_on_exit, + start_suspended, } => { if !command.is_empty() { let mut command = command.clone(); let (command, args) = (PathBuf::from(command.remove(0)), command); let cwd = cwd.or_else(|| std::env::current_dir().ok()); + let hold_on_start = start_suspended; let hold_on_close = !close_on_exit; let run_command_action = RunCommandAction { command, @@ -272,6 +274,7 @@ impl Action { cwd, direction, hold_on_close, + hold_on_start, }; if floating { Ok(vec![Action::NewFloatingPane( diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs index abb7c1e7..14b87755 100644 --- a/zellij-utils/src/input/command.rs +++ b/zellij-utils/src/input/command.rs @@ -19,6 +19,8 @@ pub struct RunCommand { pub cwd: Option<PathBuf>, #[serde(default)] pub hold_on_close: bool, + #[serde(default)] + pub hold_on_start: bool, } impl std::fmt::Display for RunCommand { @@ -50,6 +52,8 @@ pub struct RunCommandAction { pub direction: Option<Direction>, #[serde(default)] pub hold_on_close: bool, + #[serde(default)] + pub hold_on_start: bool, } impl From<RunCommandAction> for RunCommand { @@ -59,6 +63,7 @@ impl From<RunCommandAction> for RunCommand { args: action.args, cwd: action.cwd, hold_on_close: action.hold_on_close, + hold_on_start: action.hold_on_start, } } } diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index fa50237a..38806c21 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -142,7 +142,7 @@ impl Run { } } pub fn add_close_on_exit(&mut self, close_on_exit: Option<bool>) { - // overrides the args of a Run::Command if they are Some + // overrides the hold_on_close of a Run::Command if it is Some // and not empty if let Some(close_on_exit) = close_on_exit { if let Run::Command(run_command) = self { @@ -150,6 +150,15 @@ impl Run { } } } + pub fn add_start_suspended(&mut self, start_suspended: Option<bool>) { + // overrides the hold_on_start of a Run::Command if they are Some + // and not empty + if let Some(start_suspended) = start_suspended { + if let Run::Command(run_command) = self { + run_command.hold_on_start = start_suspended; + } + } + } } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index 9614eef4..f11c8686 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -282,6 +282,19 @@ fn layout_with_command_panes_and_close_on_exit() { } #[test] +fn layout_with_command_panes_and_start_suspended() { + let kdl_layout = r#" + layout { + pane command="htop" { + start_suspended true + } + } + "#; + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + assert_snapshot!(format!("{:#?}", layout)); +} + +#[test] fn layout_with_plugin_panes() { let kdl_layout = r#" layout { diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap index 6ff62582..8b6d9050 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_added_to_args_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1050 +assertion_line: 1081 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -23,6 +23,7 @@ Layout { args: [], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), @@ -45,6 +46,7 @@ Layout { ], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap index 4a449d35..4b026d75 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__args_override_args_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1033 +assertion_line: 1046 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -26,6 +26,7 @@ Layout { ], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), @@ -48,6 +49,7 @@ Layout { ], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_added_to_close_on_exit_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_added_to_close_on_exit_in_template.snap index da83cc62..d23bb40c 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_added_to_close_on_exit_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_added_to_close_on_exit_in_template.snap @@ -23,6 +23,7 @@ Layout { args: [], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), @@ -42,6 +43,7 @@ Layout { args: [], cwd: None, hold_on_close: false, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_overrides_close_on_exit_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_overrides_close_on_exit_in_template.snap index 3cb80cf7..abce2964 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_overrides_close_on_exit_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__close_on_exit_overrides_close_on_exit_in_template.snap @@ -23,6 +23,7 @@ Layout { args: [], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), @@ -42,6 +43,7 @@ Layout { args: [], cwd: None, hold_on_close: false, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_added_to_cwd_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_added_to_cwd_in_template.snap index 3c26fbdd..48bb1183 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_added_to_cwd_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_added_to_cwd_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1085 +assertion_line: 1133 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -23,6 +23,7 @@ Layout { args: [], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), @@ -44,6 +45,7 @@ Layout { "/home", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_override_cwd_in_template.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_override_cwd_in_template.snap index fd1bc15a..7d57e6d0 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_override_cwd_in_template.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__cwd_override_cwd_in_template.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1068 +assertion_line: 1116 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp", ), hold_on_close: true, + hold_on_start: false, }, ), ), @@ -46,6 +47,7 @@ Layout { "/", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd.snap index a83674d2..58a78678 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1441 +assertion_line: 1516 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp/./foo/./bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_pane_templates.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_pane_templates.snap index 8381dcd1..c6b3ed5f 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_pane_templates.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_pane_templates.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1462 +assertion_line: 1537 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -43,6 +43,7 @@ Layout { "/tmp/./foo/./bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_tab_templates.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_tab_templates.snap index 65f28704..cd1a51e1 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_tab_templates.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_and_tab_cwd_prepended_to_panes_with_and_without_cwd_in_tab_templates.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1481 +assertion_line: 1556 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp/./foo/./bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_given_to_panes_without_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_given_to_panes_without_cwd.snap index 548ae756..ba246e06 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_given_to_panes_without_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_given_to_panes_without_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1283 +assertion_line: 1403 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor.snap index d88a8ece..3b546891 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1309 +assertion_line: 1435 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor_overrides_global_cwd_in_layout_file.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor_overrides_global_cwd_in_layout_file.snap index 0710ae13..50b92892 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor_overrides_global_cwd_in_layout_file.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_passed_from_layout_constructor_overrides_global_cwd_in_layout_file.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1324 +assertion_line: 1455 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_prepended_to_panes_with_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_prepended_to_panes_with_cwd.snap index 956df1a5..f5d6b95a 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_prepended_to_panes_with_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_prepended_to_panes_with_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1295 +assertion_line: 1416 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/home/foo", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_with_tab_cwd_given_to_panes_without_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_with_tab_cwd_given_to_panes_without_cwd.snap index 4bc2f412..09d209c1 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_with_tab_cwd_given_to_panes_without_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__global_cwd_with_tab_cwd_given_to_panes_without_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1396 +assertion_line: 1471 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp/./foo", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_close_on_exit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_close_on_exit.snap index 69e3d7f1..32d1341c 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_close_on_exit.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_close_on_exit.snap @@ -23,6 +23,7 @@ Layout { args: [], cwd: None, hold_on_close: false, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_start_suspended.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_start_suspended.snap new file mode 100644 index 00000000..136c95fb --- /dev/null +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_command_panes_and_start_suspended.snap @@ -0,0 +1,42 @@ +--- +source: zellij-utils/src/input/./unit/layout_test.rs +assertion_line: 294 +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( + Command( + RunCommand { + command: "htop", + args: [], + cwd: None, + hold_on_close: true, + hold_on_start: true, + }, + ), + ), + 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__layout_with_tab_and_pane_templates.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap index f32b346d..fbe11152 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__layout_with_tab_and_pane_templates.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 570 +assertion_line: 583 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -41,6 +41,7 @@ Layout { args: [], cwd: None, hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_is_overriden_by_its_consumers_bare_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_is_overriden_by_its_consumers_bare_cwd.snap index 03adaf85..94a52aac 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_is_overriden_by_its_consumers_bare_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_is_overriden_by_its_consumers_bare_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1199 +assertion_line: 1287 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_overriden_by_its_consumers_command_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_overriden_by_its_consumers_command_cwd.snap index d01c6516..6f2255cd 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_overriden_by_its_consumers_command_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_overriden_by_its_consumers_command_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1144 +assertion_line: 1233 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/foo", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_remains_when_its_consumer_command_does_not_have_a_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_remains_when_its_consumer_command_does_not_have_a_cwd.snap index 596c492b..d659eba3 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_remains_when_its_consumer_command_does_not_have_a_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_with_cwd_remains_when_its_consumer_command_does_not_have_a_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1161 +assertion_line: 1250 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_is_overriden_by_its_consumers_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_is_overriden_by_its_consumers_cwd.snap index 25bca8db..feb8a88b 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_is_overriden_by_its_consumers_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_is_overriden_by_its_consumers_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1180 +assertion_line: 1268 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_receives_its_consumers_bare_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_receives_its_consumers_bare_cwd.snap index 05e377b9..6cad38df 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_receives_its_consumers_bare_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_command_without_cwd_receives_its_consumers_bare_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1216 +assertion_line: 1305 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_with_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_with_cwd.snap index 8c3863c3..42fb84d2 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_with_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_with_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1269 +assertion_line: 1357 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/bar", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_without_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_without_cwd.snap index ba91e574..a09f2ab2 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_without_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_command_without_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1251 +assertion_line: 1339 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -25,6 +25,7 @@ Layout { "/tmp/foo", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_given_to_panes_without_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_given_to_panes_without_cwd.snap index 8f05eda1..4508cb07 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_given_to_panes_without_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_given_to_panes_without_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1411 +assertion_line: 1486 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_prepended_to_panes_with_cwd.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_prepended_to_panes_with_cwd.snap index 32eb17d0..ac1d4240 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_prepended_to_panes_with_cwd.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__tab_cwd_prepended_to_panes_with_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1426 +assertion_line: 1501 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -39,6 +39,7 @@ Layout { "/tmp/./foo", ), hold_on_close: true, + hold_on_start: false, }, ), ), diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs index b92c6a1b..c5a84a7b 100644 --- a/zellij-utils/src/kdl/kdl_layout_parser.rs +++ b/zellij-utils/src/kdl/kdl_layout_parser.rs @@ -54,6 +54,7 @@ impl<'a> KdlLayoutParser<'a> { || word == "tab" || word == "args" || word == "close_on_exit" + || word == "start_suspended" || word == "borderless" || word == "focus" || word == "name" @@ -72,6 +73,7 @@ impl<'a> KdlLayoutParser<'a> { || property_name == "cwd" || property_name == "args" || property_name == "close_on_exit" + || property_name == "start_suspended" || property_name == "split_direction" || property_name == "pane" || property_name == "children" @@ -241,15 +243,19 @@ impl<'a> KdlLayoutParser<'a> { let args = self.parse_args(pane_node)?; let close_on_exit = kdl_get_bool_property_or_child_value_with_error!(pane_node, "close_on_exit"); + let start_suspended = + kdl_get_bool_property_or_child_value_with_error!(pane_node, "start_suspended"); if !is_template { self.assert_no_bare_attributes_in_pane_node( &command, &args, &close_on_exit, + &start_suspended, pane_node, )?; } let hold_on_close = close_on_exit.map(|c| !c).unwrap_or(true); + let hold_on_start = start_suspended.map(|c| c).unwrap_or(false); match (command, edit, cwd) { (None, None, Some(cwd)) => Ok(Some(Run::Cwd(cwd))), (Some(command), None, cwd) => Ok(Some(Run::Command(RunCommand { @@ -257,6 +263,7 @@ impl<'a> KdlLayoutParser<'a> { args: args.unwrap_or_else(|| vec![]), cwd, hold_on_close, + hold_on_start, }))), (None, Some(edit), Some(cwd)) => Ok(Some(Run::EditFile(cwd.join(edit), None))), (None, Some(edit), None) => Ok(Some(Run::EditFile(edit, None))), @@ -380,6 +387,8 @@ impl<'a> KdlLayoutParser<'a> { let args = self.parse_args(kdl_node)?; let close_on_exit = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "close_on_exit"); + let start_suspended = + kdl_get_bool_property_or_child_value_with_error!(kdl_node, "start_suspended"); let split_size = self.parse_split_size(kdl_node)?; let run = self.parse_command_plugin_or_edit_block_for_template(kdl_node)?; self.assert_no_bare_attributes_in_pane_node_with_template( @@ -387,6 +396,7 @@ impl<'a> KdlLayoutParser<'a> { &pane_template.run, &args, &close_on_exit, + &start_suspended, kdl_node, )?; self.insert_children_to_pane_template( @@ -396,10 +406,11 @@ impl<'a> KdlLayoutParser<'a> { )?; pane_template.run = Run::merge(&pane_template.run, &run); if let Some(pane_template_run_command) = pane_template.run.as_mut() { - // we need to do this because panes consuming a pane_templates + // we need to do this because panes consuming a pane_template // can have bare args without a command pane_template_run_command.add_args(args); pane_template_run_command.add_close_on_exit(close_on_exit); + pane_template_run_command.add_start_suspended(start_suspended); }; if let Some(borderless) = borderless { pane_template.borderless = borderless; @@ -600,6 +611,7 @@ impl<'a> KdlLayoutParser<'a> { pane_template_run: &Option<Run>, args: &Option<Vec<String>>, close_on_exit: &Option<bool>, + start_suspended: &Option<bool>, pane_node: &KdlNode, ) -> Result<(), ConfigError> { if let (None, None, true) = (pane_run, pane_template_run, args.is_some()) { @@ -614,6 +626,12 @@ impl<'a> KdlLayoutParser<'a> { pane_node )); } + if let (None, None, true) = (pane_run, pane_template_run, start_suspended.is_some()) { + return Err(kdl_parsing_error!( + format!("start_suspended can only be specified if a command was specified either in the pane_template or in the pane"), + pane_node + )); + } Ok(()) } fn assert_no_bare_attributes_in_pane_node( @@ -621,6 +639,7 @@ impl<'a> KdlLayoutParser<'a> { command: &Option<PathBuf>, args: &Option<Vec<String>>, close_on_exit: &Option<bool>, + start_suspended: &Option<bool>, pane_node: &KdlNode, ) -> Result<(), ConfigError> { if command.is_none() { @@ -631,6 +650,13 @@ impl<'a> KdlLayoutParser<'a> { pane_node.span().len(), )); } + if start_suspended.is_some() { + return Err(ConfigError::new_layout_kdl_error( + "start_suspended can only be set if a command was specified".into(), + pane_node.span().offset(), + pane_node.span().len(), + )); + } if args.is_some() { return Err(ConfigError::new_layout_kdl_error( "args can only be set if a command was specified".into(), diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index 92abcac1..54560bf5 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1,7 +1,6 @@ mod kdl_layout_parser; use crate::data::{InputMode, Key, Palette, PaletteColor}; use crate::envs::EnvironmentVariables; -use crate::input::command::RunCommand; use crate::input::config::{Config, ConfigError, KdlError}; use crate::input::keybinds::Keybinds; use crate::input::layout::{Layout, RunPlugin, RunPluginLocation}; @@ -339,6 +338,16 @@ pub fn kdl_child_string_value_for_entry<'a>( .and_then(|cwd_value| cwd_value.value().as_string()) } +pub fn kdl_child_bool_value_for_entry<'a>( + command_metadata: &'a KdlDocument, + entry_name: &'a str, +) -> Option<bool> { + command_metadata + .get(entry_name) + .and_then(|cwd| cwd.entries().iter().next()) + .and_then(|cwd_value| cwd_value.value().as_bool()) +} + impl Action { pub fn new_from_bytes( action_name: &str, @@ -741,12 +750,20 @@ impl TryFrom<&KdlNode> for Action { let direction = command_metadata .and_then(|c_m| kdl_child_string_value_for_entry(c_m, "direction")) .and_then(|direction_string| Direction::from_str(direction_string).ok()); + let hold_on_close = command_metadata + .and_then(|c_m| kdl_child_bool_value_for_entry(c_m, "close_on_exit")) + .and_then(|close_on_exit| Some(!close_on_exit)) + .unwrap_or(true); + let hold_on_start = command_metadata + .and_then(|c_m| kdl_child_bool_value_for_entry(c_m, "start_suspended")) + .unwrap_or(false); let run_command_action = RunCommandAction { command: PathBuf::from(command), args, cwd, direction, - hold_on_close: true, + hold_on_close, + hold_on_start, }; Ok(Action::Run(run_command_action)) }, @@ -1464,32 +1481,6 @@ impl Keybinds { } } -impl RunCommand { - pub fn from_kdl(kdl_node: &KdlNode) -> Result<Self, ConfigError> { - let command = PathBuf::from(kdl_get_child_entry_string_value!(kdl_node, "cmd").ok_or( - ConfigError::new_kdl_error( - "Command must have a cmd value".into(), - kdl_node.span().offset(), - kdl_node.span().len(), - ), - )?); - let cwd = kdl_get_child_entry_string_value!(kdl_node, "cwd").map(|c| PathBuf::from(c)); - let args = match kdl_get_child!(kdl_node, "args") { - Some(kdl_args) => kdl_string_arguments!(kdl_args) - .iter() - .map(|s| String::from(*s)) - .collect(), - None => vec![], - }; - Ok(RunCommand { - command, - args, - cwd, - hold_on_close: true, - }) - } -} - impl Config { pub fn from_kdl(kdl_config: &str, base_config: Option<Config>) -> Result<Config, ConfigError> { let mut config = base_config.unwrap_or_else(|| Config::default()); |
