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-server/src/tab | |
parent | 6d29c6951e4768cc6f2f3c7b1bbb708d79d860c9 (diff) |
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-server/src/tab')
-rw-r--r-- | zellij-server/src/tab/mod.rs | 29 | ||||
-rw-r--r-- | zellij-server/src/tab/unit/tab_integration_tests.rs | 16 | ||||
-rw-r--r-- | zellij-server/src/tab/unit/tab_tests.rs | 4 |
3 files changed, 28 insertions, 21 deletions
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index 9efcf9012..df12b2df9 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -61,6 +61,8 @@ macro_rules! resize_pty { }; } +type HoldForCommand = Option<RunCommand>; + // FIXME: This should be replaced by `RESIZE_PERCENT` at some point pub const MIN_TERMINAL_HEIGHT: usize = 5; pub const MIN_TERMINAL_WIDTH: usize = 5; @@ -354,7 +356,7 @@ pub trait Pane { // False by default (only terminal-panes support alternate mode) false } - fn hold(&mut self, _exit_status: Option<i32>, _run_command: RunCommand) { + fn hold(&mut self, _exit_status: Option<i32>, _is_first_run: bool, _run_command: RunCommand) { // No-op by default, only terminal panes support holding } } @@ -470,7 +472,7 @@ impl Tab { pub fn apply_layout( &mut self, layout: PaneLayout, - new_ids: Vec<u32>, + new_ids: Vec<(u32, HoldForCommand)>, tab_index: usize, client_id: ClientId, ) -> Result<()> { @@ -532,7 +534,7 @@ impl Tab { set_focus_pane_id(layout, PaneId::Plugin(pid)); } else { // there are still panes left to fill, use the pids we received in this method - if let Some(pid) = new_ids.next() { + if let Some((pid, hold_for_command)) = new_ids.next() { let next_terminal_position = self.get_next_terminal_position(); let initial_title = match &layout.run { Some(Run::Command(run_command)) => Some(run_command.to_string()), @@ -552,6 +554,9 @@ impl Tab { initial_title, ); new_pane.set_borderless(layout.borderless); + if let Some(held_command) = hold_for_command { + new_pane.hold(None, true, held_command.clone()); + } self.tiled_panes.add_pane_with_existing_geom( PaneId::Terminal(*pid), Box::new(new_pane), @@ -560,7 +565,7 @@ impl Tab { } } } - for unused_pid in new_ids { + for (unused_pid, _) in new_ids { // this is a bit of a hack and happens because we don't have any central location that // can query the screen as to how many panes it needs to create a layout // fixing this will require a bit of an architecture change @@ -601,7 +606,7 @@ impl Tab { Ok(()) }, Err(e) => { - for unused_pid in new_ids { + for (unused_pid, _) in new_ids { self.senders .send_to_pty(PtyInstruction::ClosePane(PaneId::Terminal(unused_pid))) .with_context(err_context)?; @@ -1746,11 +1751,19 @@ impl Tab { closed_pane } } - pub fn hold_pane(&mut self, id: PaneId, exit_status: Option<i32>, run_command: RunCommand) { + pub fn hold_pane( + &mut self, + id: PaneId, + exit_status: Option<i32>, + is_first_run: bool, + run_command: RunCommand, + ) { if self.floating_panes.panes_contain(&id) { - self.floating_panes.hold_pane(id, exit_status, run_command); + self.floating_panes + .hold_pane(id, exit_status, is_first_run, run_command); } else { - self.tiled_panes.hold_pane(id, exit_status, run_command); + self.tiled_panes + .hold_pane(id, exit_status, is_first_run, run_command); } } pub fn replace_pane_with_suppressed_pane(&mut self, pane_id: PaneId) -> Option<Box<dyn Pane>> { diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs index 5944f84d0..3f4290fa6 100644 --- a/zellij-server/src/tab/unit/tab_integration_tests.rs +++ b/zellij-server/src/tab/unit/tab_integration_tests.rs @@ -223,7 +223,7 @@ fn create_new_tab(size: Size, default_mode: ModeInfo) -> Tab { terminal_emulator_colors, terminal_emulator_color_codes, ); - tab.apply_layout(PaneLayout::default(), vec![1], index, client_id) + tab.apply_layout(PaneLayout::default(), vec![(1, None)], index, client_id) .unwrap(); tab } @@ -277,7 +277,7 @@ fn create_new_tab_with_layout(size: Size, default_mode: ModeInfo, layout: &str) .extract_run_instructions() .iter() .enumerate() - .map(|(i, _)| i as u32) + .map(|(i, _)| (i as u32, None)) .collect(); tab.apply_layout(tab_layout, pane_ids, index, client_id) .unwrap(); @@ -332,14 +332,8 @@ fn create_new_tab_with_mock_pty_writer( terminal_emulator_colors, terminal_emulator_color_codes, ); - tab.apply_layout( - // LayoutTemplate::default().try_into().unwrap(), - PaneLayout::default(), - vec![1], - index, - client_id, - ) - .unwrap(); + tab.apply_layout(PaneLayout::default(), vec![(1, None)], index, client_id) + .unwrap(); tab } @@ -393,7 +387,7 @@ fn create_new_tab_with_sixel_support( terminal_emulator_colors, terminal_emulator_color_codes, ); - tab.apply_layout(PaneLayout::default(), vec![1], index, client_id) + tab.apply_layout(PaneLayout::default(), vec![(1, None)], index, client_id) .unwrap(); tab } diff --git a/zellij-server/src/tab/unit/tab_tests.rs b/zellij-server/src/tab/unit/tab_tests.rs index 6b100cf62..2539b7a93 100644 --- a/zellij-server/src/tab/unit/tab_tests.rs +++ b/zellij-server/src/tab/unit/tab_tests.rs @@ -142,7 +142,7 @@ fn create_new_tab(size: Size) -> Tab { terminal_emulator_colors, terminal_emulator_color_codes, ); - tab.apply_layout(PaneLayout::default(), vec![1], index, client_id) + tab.apply_layout(PaneLayout::default(), vec![(1, None)], index, client_id) .unwrap(); tab } @@ -189,7 +189,7 @@ fn create_new_tab_with_cell_size( terminal_emulator_colors, terminal_emulator_color_codes, ); - tab.apply_layout(PaneLayout::default(), vec![1], index, client_id) + tab.apply_layout(PaneLayout::default(), vec![(1, None)], index, client_id) .unwrap(); tab } |