Skip to content

Commit

Permalink
feat: Add layout configuration to exclude panes from tab sync
Browse files Browse the repository at this point in the history
  • Loading branch information
on3iro committed Apr 15, 2023
1 parent 03c507b commit a9c5fb5
Show file tree
Hide file tree
Showing 56 changed files with 461 additions and 13 deletions.
8 changes: 8 additions & 0 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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![(
Expand Down
10 changes: 10 additions & 0 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions zellij-server/src/tab/layout_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
}
Expand Down
31 changes: 24 additions & 7 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: zellij-server/src/./unit/screen_tests.rs
assertion_line: 2397
expression: "format!(\"{:#?}\", new_tab_action)"
---
Some(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -43,6 +44,7 @@ Some(
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
),
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -66,6 +69,7 @@ NewTab(
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
),
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
),
[],
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
),
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
),
[],
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
),
[],
Expand Down
1 change: 1 addition & 0 deletions zellij-utils/src/input/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ pub struct TiledPaneLayout {
pub external_children_index: Option<usize>,
pub children_are_stacked: bool,
pub is_expanded_in_stack: bool,
pub exclude_from_sync: Option<bool>,
}

impl TiledPaneLayout {
Expand Down
11 changes: 11 additions & 0 deletions zellij-utils/src/input/unit/layout_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,17 @@ fn combined_tab_and_pane_template_both_with_children() {
assert_snapshot!(format!("{:#?}", layout));
}

#[test]
fn layout_with_pane_excluded_from_sync() {
let kdl_layout = r#"
layout {
pane exclude_from_sync=true
}
"#;
let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap();
assert_snapshot!(format!("{:#?}", layout));
}

#[test]
fn cannot_define_tab_template_name_with_space() {
let kdl_layout = r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
TiledPaneLayout {
children_split_direction: Horizontal,
Expand All @@ -58,6 +59,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
],
split_size: None,
Expand All @@ -67,6 +69,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
[],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
TiledPaneLayout {
children_split_direction: Horizontal,
Expand All @@ -61,6 +62,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
],
split_size: None,
Expand All @@ -70,6 +72,7 @@ Layout {
external_children_index: None,
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
},
[],
),
Expand Down
Loading

0 comments on commit a9c5fb5

Please sign in to comment.