diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-10-17 19:39:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 19:39:37 +0200 |
commit | 271abb3ea2842cadc131ae91a3cd899e320e958e (patch) | |
tree | b20d4231f6d5b46737efe6b60b4e4e0170a87640 /zellij-server | |
parent | 4562982409cfcdfc151c5a4c2878d358dac9e76c (diff) |
feat(cli): zellij run improvements (#1804)
* feat(cli): move command to the end of the cli arguments
* feat(cli): allow naming panes from the command line
* fix(cli): adjust actions after pane rename
* feat(cli): zellij run completions for fish
* feat(cli): zellij run completions for bash and zsh
* style(fmt): rustfmt
* fix(e2e): fix run test and snapshot
* style(fmt): rustfmt
Diffstat (limited to 'zellij-server')
12 files changed, 88 insertions, 54 deletions
diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 95ddf9828..15e546f26 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -343,9 +343,7 @@ impl Pane for TerminalPane { input_mode: InputMode, ) -> Option<(Vec<CharacterChunk>, Option<String>)> { // TODO: remove the cursor stuff from here - let pane_title = if let Some((_exit_status, run_command)) = &self.is_held { - format!("{}", run_command) - } else if self.pane_name.is_empty() + let pane_title = if self.pane_name.is_empty() && input_mode == InputMode::RenamePane && frame_params.is_main_client { diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 9151c1a15..9fa8e1966 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -31,11 +31,20 @@ pub enum ClientOrTabIndex { /// Instructions related to PTYs (pseudoterminals). #[derive(Clone, Debug)] pub(crate) enum PtyInstruction { - SpawnTerminal(Option<TerminalAction>, Option<bool>, ClientOrTabIndex), // bool (if Some) is - // should_float + SpawnTerminal( + Option<TerminalAction>, + Option<bool>, + Option<String>, + ClientOrTabIndex, + ), // bool (if Some) is + // should_float, String is an optional pane name OpenInPlaceEditor(PathBuf, Option<usize>, ClientId), // Option<usize> is the optional line number - SpawnTerminalVertically(Option<TerminalAction>, ClientId), - SpawnTerminalHorizontally(Option<TerminalAction>, ClientId), + SpawnTerminalVertically(Option<TerminalAction>, Option<String>, ClientId), // String is an + // optional pane + // name + SpawnTerminalHorizontally(Option<TerminalAction>, Option<String>, ClientId), // String is an + // optional pane + // name UpdateActivePane(Option<PaneId>, ClientId), GoToTab(TabIndex, ClientId), NewTab( @@ -82,14 +91,19 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) { let (event, mut err_ctx) = pty.bus.recv().expect("failed to receive event on channel"); err_ctx.add_call(ContextType::Pty((&event).into())); match event { - PtyInstruction::SpawnTerminal(terminal_action, should_float, client_or_tab_index) => { + PtyInstruction::SpawnTerminal( + terminal_action, + should_float, + name, + client_or_tab_index, + ) => { let (hold_on_close, run_command, pane_title) = match &terminal_action { Some(TerminalAction::RunCommand(run_command)) => ( run_command.hold_on_close, Some(run_command.clone()), - Some(run_command.to_string()), + Some(name.unwrap_or_else(|| run_command.to_string())), ), - _ => (false, None, None), + _ => (false, None, name), }; match pty.spawn_terminal(terminal_action, client_or_tab_index) { Ok(pid) => { @@ -149,14 +163,14 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) { }, } }, - PtyInstruction::SpawnTerminalVertically(terminal_action, client_id) => { + PtyInstruction::SpawnTerminalVertically(terminal_action, name, client_id) => { let (hold_on_close, run_command, pane_title) = match &terminal_action { Some(TerminalAction::RunCommand(run_command)) => ( run_command.hold_on_close, Some(run_command.clone()), - Some(run_command.to_string()), + Some(name.unwrap_or_else(|| run_command.to_string())), ), - _ => (false, None, None), + _ => (false, None, name), }; match pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id)) { Ok(pid) => { @@ -209,14 +223,14 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) { }, } }, - PtyInstruction::SpawnTerminalHorizontally(terminal_action, client_id) => { + PtyInstruction::SpawnTerminalHorizontally(terminal_action, name, client_id) => { let (hold_on_close, run_command, pane_title) = match &terminal_action { Some(TerminalAction::RunCommand(run_command)) => ( run_command.hold_on_close, Some(run_command.clone()), - Some(run_command.to_string()), + Some(name.unwrap_or_else(|| run_command.to_string())), ), - _ => (false, None, None), + _ => (false, None, name), }; match pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id)) { Ok(pid) => { diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index fc8722b44..1fae23186 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -235,43 +235,56 @@ pub(crate) fn route_action( .send_to_screen(ScreenInstruction::TogglePaneFrames) .unwrap(); }, - Action::NewPane(direction) => { + Action::NewPane(direction, name) => { let shell = session.default_shell.clone(); let pty_instr = match direction { - Some(Direction::Left) => PtyInstruction::SpawnTerminalVertically(shell, client_id), - Some(Direction::Right) => PtyInstruction::SpawnTerminalVertically(shell, client_id), - Some(Direction::Up) => PtyInstruction::SpawnTerminalHorizontally(shell, client_id), + Some(Direction::Left) => { + PtyInstruction::SpawnTerminalVertically(shell, name, client_id) + }, + Some(Direction::Right) => { + PtyInstruction::SpawnTerminalVertically(shell, name, client_id) + }, + Some(Direction::Up) => { + PtyInstruction::SpawnTerminalHorizontally(shell, name, client_id) + }, Some(Direction::Down) => { - PtyInstruction::SpawnTerminalHorizontally(shell, client_id) + PtyInstruction::SpawnTerminalHorizontally(shell, name, client_id) }, // No direction specified - try to put it in the biggest available spot None => PtyInstruction::SpawnTerminal( shell, None, + name, ClientOrTabIndex::ClientId(client_id), ), }; session.senders.send_to_pty(pty_instr).unwrap(); }, Action::EditFile(path_to_file, line_number, split_direction, should_float) => { + let title = format!("Editing: {}", path_to_file.display()); let open_file = TerminalAction::OpenFile(path_to_file, line_number); let pty_instr = match (split_direction, should_float) { (Some(Direction::Left), false) => { - PtyInstruction::SpawnTerminalVertically(Some(open_file), client_id) + PtyInstruction::SpawnTerminalVertically(Some(open_file), Some(title), client_id) }, (Some(Direction::Right), false) => { - PtyInstruction::SpawnTerminalVertically(Some(open_file), client_id) - }, - (Some(Direction::Up), false) => { - PtyInstruction::SpawnTerminalHorizontally(Some(open_file), client_id) - }, - (Some(Direction::Down), false) => { - PtyInstruction::SpawnTerminalHorizontally(Some(open_file), client_id) + PtyInstruction::SpawnTerminalVertically(Some(open_file), Some(title), client_id) }, + (Some(Direction::Up), false) => PtyInstruction::SpawnTerminalHorizontally( + Some(open_file), + Some(title), + client_id, + ), + (Some(Direction::Down), false) => PtyInstruction::SpawnTerminalHorizontally( + Some(open_file), + Some(title), + client_id, + ), // No direction specified or should float - defer placement to screen (None, _) | (_, true) => PtyInstruction::SpawnTerminal( Some(open_file), Some(should_float), + Some(title), ClientOrTabIndex::ClientId(client_id), ), }; @@ -296,7 +309,7 @@ pub(crate) fn route_action( ))) .unwrap(); }, - Action::NewFloatingPane(run_command) => { + Action::NewFloatingPane(run_command, name) => { let should_float = true; let run_cmd = run_command .map(|cmd| TerminalAction::RunCommand(cmd.into())) @@ -306,32 +319,34 @@ pub(crate) fn route_action( .send_to_pty(PtyInstruction::SpawnTerminal( run_cmd, Some(should_float), + name, ClientOrTabIndex::ClientId(client_id), )) .unwrap(); }, - Action::NewTiledPane(direction, run_command) => { + Action::NewTiledPane(direction, run_command, name) => { let should_float = false; let run_cmd = run_command .map(|cmd| TerminalAction::RunCommand(cmd.into())) .or_else(|| session.default_shell.clone()); let pty_instr = match direction { Some(Direction::Left) => { - PtyInstruction::SpawnTerminalVertically(run_cmd, client_id) + PtyInstruction::SpawnTerminalVertically(run_cmd, name, client_id) }, Some(Direction::Right) => { - PtyInstruction::SpawnTerminalVertically(run_cmd, client_id) + PtyInstruction::SpawnTerminalVertically(run_cmd, name, client_id) }, Some(Direction::Up) => { - PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id) + PtyInstruction::SpawnTerminalHorizontally(run_cmd, name, client_id) }, Some(Direction::Down) => { - PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id) + PtyInstruction::SpawnTerminalHorizontally(run_cmd, name, client_id) }, // No direction specified - try to put it in the biggest available spot None => PtyInstruction::SpawnTerminal( run_cmd, Some(should_float), + name, ClientOrTabIndex::ClientId(client_id), ), }; @@ -368,21 +383,22 @@ pub(crate) fn route_action( let run_cmd = Some(TerminalAction::RunCommand(command.clone().into())); let pty_instr = match command.direction { Some(Direction::Left) => { - PtyInstruction::SpawnTerminalVertically(run_cmd, client_id) + PtyInstruction::SpawnTerminalVertically(run_cmd, None, client_id) }, Some(Direction::Right) => { - PtyInstruction::SpawnTerminalVertically(run_cmd, client_id) + PtyInstruction::SpawnTerminalVertically(run_cmd, None, client_id) }, Some(Direction::Up) => { - PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id) + PtyInstruction::SpawnTerminalHorizontally(run_cmd, None, client_id) }, Some(Direction::Down) => { - PtyInstruction::SpawnTerminalHorizontally(run_cmd, client_id) + PtyInstruction::SpawnTerminalHorizontally(run_cmd, None, client_id) }, // No direction specified - try to put it in the biggest available spot None => PtyInstruction::SpawnTerminal( run_cmd, None, + None, ClientOrTabIndex::ClientId(client_id), ), }; diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index 064141f74..e8809b8ee 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -780,10 +780,12 @@ impl Tab { } }, None => { + let name = None; let should_float = true; let instruction = PtyInstruction::SpawnTerminal( default_shell, Some(should_float), + name, ClientOrTabIndex::ClientId(client_id), ); self.senders.send_to_pty(instruction).with_context(|| { diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index 0ab13bf94..c19f364ee 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -1815,9 +1815,10 @@ pub fn send_cli_new_pane_action_with_default_parameters() { ); let cli_new_pane_action = CliAction::NewPane { direction: None, - command: None, + command: vec![], cwd: None, floating: false, + name: None, }; send_cli_action_to_server( &session_metadata, @@ -1852,9 +1853,10 @@ pub fn send_cli_new_pane_action_with_split_direction() { ); let cli_new_pane_action = CliAction::NewPane { direction: Some(Direction::Right), - command: None, + command: vec![], cwd: None, floating: false, + name: None, }; send_cli_action_to_server( &session_metadata, @@ -1889,9 +1891,10 @@ pub fn send_cli_new_pane_action_with_command_and_cwd() { ); let cli_new_pane_action = CliAction::NewPane { direction: Some(Direction::Right), - command: Some("htop".into()), + command: vec!["htop".into()], cwd: Some("/some/folder".into()), floating: false, + name: None, }; send_cli_action_to_server( &session_metadata, diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap index 15573f908..649328fe4 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 1937 +assertion_line: 1944 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminal(Some(OpenFile("/file/to/edit", None)), Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminal(Some(OpenFile("/file/to/edit", None)), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap index aed92a477..e8f819d8f 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 1974 +assertion_line: 1981 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100))), Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100))), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap index 9bdefbb1f..3280a24e4 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2011 +assertion_line: 2018 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None)), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None)), Some("Editing: /file/to/edit"), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_command_and_cwd.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_command_and_cwd.snap index 315ba02d8..62d76f63b 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_command_and_cwd.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_command_and_cwd.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 1900 +assertion_line: 1907 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminalVertically(Some(RunCommand(RunCommand { command: "htop", args: [], cwd: Some("/some/folder"), hold_on_close: true })), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminalVertically(Some(RunCommand(RunCommand { command: "htop", args: [], cwd: Some("/some/folder"), hold_on_close: true })), None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_default_parameters.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_default_parameters.snap index 6153c4c12..305dd0df4 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_default_parameters.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_default_parameters.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 1826 +assertion_line: 1831 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminal(None, Some(false), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminal(None, Some(false), None, ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_split_direction.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_split_direction.snap index f66107e9f..50d0d59c5 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_split_direction.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_pane_action_with_split_direction.snap @@ -1,6 +1,6 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 1863 +assertion_line: 1869 expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())" --- -[SpawnTerminalVertically(None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] +[SpawnTerminalVertically(None, None, 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit] diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index cfef982a3..87b230eb9 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -395,6 +395,7 @@ fn host_open_file(plugin_env: &PluginEnv) { .send_to_pty(PtyInstruction::SpawnTerminal( Some(TerminalAction::OpenFile(path, None)), None, + None, ClientOrTabIndex::TabIndex(plugin_env.tab_index), )) .unwrap(); |