diff options
author | Theo Salzmann <dev@on3iro.de> | 2023-04-18 16:33:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 16:33:20 +0200 |
commit | 525928b18a05d8662b5de7e85987428d84c0cb7d (patch) | |
tree | 03654c4d59cc6c1902ac90f3b497f2892c58f749 /zellij-server/src | |
parent | c7bd2ce9222d328369216ba287c57752910e0e88 (diff) |
feat: Add layout configuration to exclude panes from tab sync (#2314)
Diffstat (limited to 'zellij-server/src')
8 files changed, 67 insertions, 8 deletions
diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs index 980438c57..8a45c3c10 100644 --- a/zellij-server/src/panes/plugin_pane.rs +++ b/zellij-server/src/panes/plugin_pane.rs @@ -68,6 +68,7 @@ pub(crate) struct PluginPane { prev_pane_name: String, frame: HashMap<ClientId, PaneFrame>, borderless: bool, + exclude_from_sync: bool, pane_frame_color_override: Option<(PaletteColor, Option<String>)>, invoked_with: Option<Run>, loading_indication: LoadingIndication, @@ -107,6 +108,7 @@ impl PluginPane { prev_pane_name: pane_name, terminal_emulator_colors, terminal_emulator_color_codes, + exclude_from_sync: false, link_handler, character_cell_size, sixel_image_store, @@ -502,6 +504,12 @@ impl Pane for PluginPane { fn borderless(&self) -> bool { self.borderless } + fn set_exclude_from_sync(&mut self, exclude_from_sync: bool) { + self.exclude_from_sync = exclude_from_sync; + } + fn exclude_from_sync(&self) -> bool { + self.exclude_from_sync + } fn handle_right_click(&mut self, to: &Position, client_id: ClientId) { self.send_plugin_instructions .send(PluginInstruction::Update(vec![( diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 469cfa093..0c1b55070 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -105,6 +105,7 @@ pub struct TerminalPane { prev_pane_name: String, frame: HashMap<ClientId, PaneFrame>, borderless: bool, + exclude_from_sync: bool, fake_cursor_locations: HashSet<(usize, usize)>, // (x, y) - these hold a record of previous fake cursors which we need to clear on render search_term: String, is_held: Option<(Option<i32>, IsFirstRun, RunCommand)>, // a "held" pane means that its command has either exited and the pane is waiting for a @@ -602,6 +603,14 @@ impl Pane for TerminalPane { self.borderless } + fn set_exclude_from_sync(&mut self, exclude_from_sync: bool) { + self.exclude_from_sync = exclude_from_sync; + } + + fn exclude_from_sync(&self) -> bool { + self.exclude_from_sync + } + fn mouse_left_click(&self, position: &Position, is_held: bool) -> Option<String> { self.grid.mouse_left_click_signal(position, is_held) } @@ -756,6 +765,7 @@ impl TerminalPane { pane_name: pane_name.clone(), prev_pane_name: pane_name, borderless: false, + exclude_from_sync: false, fake_cursor_locations: HashSet::new(), search_term: String::new(), is_held: None, diff --git a/zellij-server/src/tab/layout_applier.rs b/zellij-server/src/tab/layout_applier.rs index ef475c07e..a89a42dc4 100644 --- a/zellij-server/src/tab/layout_applier.rs +++ b/zellij-server/src/tab/layout_applier.rs @@ -235,6 +235,9 @@ impl<'a> LayoutApplier<'a> { layout.run.clone(), ); new_plugin.set_borderless(layout.borderless); + if let Some(exclude_from_sync) = layout.exclude_from_sync { + new_plugin.set_exclude_from_sync(exclude_from_sync); + } self.tiled_panes .add_pane_with_existing_geom(PaneId::Plugin(pid), Box::new(new_plugin)); set_focus_pane_id(layout, PaneId::Plugin(pid)); @@ -262,6 +265,9 @@ impl<'a> LayoutApplier<'a> { layout.run.clone(), ); new_pane.set_borderless(layout.borderless); + if let Some(exclude_from_sync) = layout.exclude_from_sync { + new_pane.set_exclude_from_sync(exclude_from_sync); + } if let Some(held_command) = hold_for_command { new_pane.hold(None, true, held_command.clone()); } diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index d61eb1a4c..65228b83a 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -371,6 +371,9 @@ pub trait Pane { fn load_pane_name(&mut self); fn set_borderless(&mut self, borderless: bool); fn borderless(&self) -> bool; + fn set_exclude_from_sync(&mut self, exclude_from_sync: bool); + fn exclude_from_sync(&self) -> bool; + // TODO: this should probably be merged with the mouse_right_click fn handle_right_click(&mut self, _to: &Position, _client_id: ClientId) {} fn mouse_left_click(&self, _position: &Position, _is_held: bool) -> Option<String> { @@ -1656,15 +1659,29 @@ impl Tab { let err_context = || format!("failed to write to pane with id {pane_id:?}"); let mut should_update_ui = false; + let is_sync_panes_active = self.is_sync_panes_active(); + + let active_terminal = self + .floating_panes + .get_mut(&pane_id) + .or_else(|| self.tiled_panes.get_pane_mut(pane_id)) + .or_else(|| self.suppressed_panes.get_mut(&pane_id)) + .ok_or_else(|| anyhow!(format!("failed to find pane with id {pane_id:?}"))) + .with_context(err_context)?; + + // We always write for non-synced terminals. + // However if the terminal is part of a tab-sync, we need to + // check if the terminal should receive input or not (depending on its + // 'exclude_from_sync' configuration). + let should_not_write_to_terminal = + is_sync_panes_active && active_terminal.exclude_from_sync(); + + if should_not_write_to_terminal { + return Ok(should_update_ui); + } + match pane_id { PaneId::Terminal(active_terminal_id) => { - let active_terminal = self - .floating_panes - .get_mut(&pane_id) - .or_else(|| self.tiled_panes.get_pane_mut(pane_id)) - .or_else(|| self.suppressed_panes.get_mut(&pane_id)) - .ok_or_else(|| anyhow!(format!("failed to find pane with id {pane_id:?}"))) - .with_context(err_context)?; match active_terminal.adjust_input_to_terminal(input_bytes) { Some(AdjustedInput::WriteBytesToTerminal(adjusted_input)) => { self.senders diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap index 45e58cf70..42eeaa7c4 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_default_params.snap @@ -1,6 +1,5 @@ --- source: zellij-server/src/./unit/screen_tests.rs -assertion_line: 2397 expression: "format!(\"{:#?}\", new_tab_action)" --- Some( @@ -22,6 +21,7 @@ Some( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -34,6 +34,7 @@ Some( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -43,6 +44,7 @@ Some( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap index d09628ded..f06ae128c 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_new_tab_action_with_name_and_layout.snap @@ -25,6 +25,7 @@ NewTab( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -41,6 +42,7 @@ NewTab( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -57,6 +59,7 @@ NewTab( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -66,6 +69,7 @@ NewTab( external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap index c0312eb7b..596b5e800 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_rename_tab.snap @@ -44,6 +44,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -56,6 +57,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -65,6 +67,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], @@ -201,6 +204,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -213,6 +217,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -222,6 +227,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap index 525bb97d3..1a80ff086 100644 --- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap +++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_undo_rename_tab.snap @@ -44,6 +44,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -56,6 +57,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -65,6 +67,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], @@ -201,6 +204,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, TiledPaneLayout { children_split_direction: Horizontal, @@ -213,6 +217,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ], split_size: None, @@ -222,6 +227,7 @@ expression: "format!(\"{:#?}\", * received_plugin_instructions.lock().unwrap())" external_children_index: None, children_are_stacked: false, is_expanded_in_stack: false, + exclude_from_sync: None, }, ), [], |