aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2025-12-11 14:25:42 +0100
committerGitHub <noreply@github.com>2025-12-11 14:25:42 +0100
commit693fa082def5ef0fe030cd7fdc3b1df051b35dc6 (patch)
treeb3f651462bbc1cd2fa5b2d79207343413ef6b83c /zellij-server/src/panes
parentfix(zellij-server): unblock building on 32bit targets (#4484) (diff)
downloadsl0ppij-693fa082def5ef0fe030cd7fdc3b1df051b35dc6.tar.gz
sl0ppij-693fa082def5ef0fe030cd7fdc3b1df051b35dc6.tar.xz
sl0ppij-693fa082def5ef0fe030cd7fdc3b1df051b35dc6.zip
Command Sequences, Blocking CLI Commands, New Plugin APIs (#4546)
* fix deadlocks * initial logging to plugin implementation * only log actions, include keys as Action::Write * send actions to plugins as a new Event::UserAction * add Action::Write metadata to plugin API * run_action plugin command and permission * block-until-exit/success/failure in the cli * fix tests * add NewBlockingPane to the plugin API * run actions in a different thread so as not to block plugin execution * add custom context to run_action flow * fixes for floating pane z_index sorting and unknown protobuf events not crashing plugins * always render the frame of pinned panes * macros module * add macros to config * KDL macro parsing * thread macros to the plugin thread * get/update/delete macros from plugins * add macros updated event * add ability to rename macros * fix deadlock * fix z_indices with pinned unselectable panes bug * allow plugins to opt-in to show_cursor * change show_cursor(bool) to show_cursor(Option<coordinates>) * test * upgrade strum to allow proper enum iteration and case insensitive fromstr implementation for Actions * better cwd tracking for exited command panes * add initial panes to NewTab Action (no-op for now) * add initial panes to cli newtab action * make initial panes work * add close_on_exit and start_suspended to the cli * properly convert newtab action (potentially breaking for plugins) * allow first pane in tab to block * make distinction between opening panes with the last active client and the current pane in the cli * improve some apis * fix fixed size closing pane bug * fix plugin cursor coordinates * fix issues with launch-or-focus-plugin having to do with in-place and suppressed panes * fix: set affected pane in replace pane * allow setting a pane in place when it is suppressed and being focused (tests failing) * fix tests * some fixes for unsuppression of panes * some fixes for completion_tx in new tab action * allow replace/suppressed rather than replace/close only * fixes for inserting suppressed panes without conflicts * pane focus history and explicit unsuppress plugin api * fix: prefer explicitly provided pane id in placement in actions that provide it * fix floating pane coordinate change and z_index * fix plugin cache dir to persist between sessions * fix some stack focusing issues when adding panes without a client id * make sure pinned panes are always above non-pinned floating panes * allow plugins to copy to clipboard * initial text styling additions implementations - buggy * fix dimming issues * remove extras, stay with just dim and unbold * unbold and dim as indices * allow ui components to render success/error colors * allow plugins to send sigint/sigkill to processes, as well as receive their pid * ui component fixes and send originating plugin context with run_action * originating plugin for new tab too * make plugn show pane command also expand stacked panes * add sequence plugin * remove macros * remove snapshots * add shortcut for sequence plugin * fix plugin tests * plugin tests for new apis * update snapshots for sequence shortcut * cleanups and formatting * Event::CwdChanged * moar cleanups * remove some warnings * remove mroe warnings * remove dead code * remove more dead code * fix minor bugs in sequence plugin * update sequence help and format codebase * fix conditional blocking cli commands * fix initial-command new-tab cli flag * add client_ids to CwdChanged Event * last fixes * add pr
Diffstat (limited to 'zellij-server/src/panes')
-rw-r--r--zellij-server/src/panes/floating_panes/mod.rs59
-rw-r--r--zellij-server/src/panes/plugin_pane.rs29
-rw-r--r--zellij-server/src/panes/terminal_pane.rs22
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs8
-rw-r--r--zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs8
-rw-r--r--zellij-server/src/panes/tiled_panes/unit/stacked_panes_tests.rs2
-rw-r--r--zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__table_ui_component.snap14
7 files changed, 110 insertions, 32 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs
index 6ae71b43..d347dcd0 100644
--- a/zellij-server/src/panes/floating_panes/mod.rs
+++ b/zellij-server/src/panes/floating_panes/mod.rs
@@ -18,6 +18,7 @@ use crate::{
ClientId,
};
use std::cell::RefCell;
+use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use std::time::Instant;
@@ -129,6 +130,7 @@ impl FloatingPanes {
.insert(pane_id, pane.position_and_size());
self.panes.insert(pane_id, pane);
self.z_indices.push(pane_id);
+ self.make_sure_pinned_panes_are_on_top();
}
pub fn replace_active_pane(
&mut self,
@@ -169,6 +171,7 @@ impl FloatingPanes {
.with_context(err_context)?;
self.z_indices.remove(z_index);
self.z_indices.insert(z_index, with_pane_id);
+ self.make_sure_pinned_panes_are_on_top();
Ok(removed_pane)
});
@@ -415,21 +418,10 @@ impl FloatingPanes {
vec![]
};
floating_panes.sort_by(|(a_id, _a_pane), (b_id, _b_pane)| {
- self.z_indices
- .iter()
- .position(|id| id == *a_id)
- .with_context(err_context)
- .fatal()
- .cmp(
- &self
- .z_indices
- .iter()
- .position(|id| id == *b_id)
- .with_context(err_context)
- .fatal(),
- )
+ let a_pos = self.z_indices.iter().position(|id| id == *a_id);
+ let b_pos = self.z_indices.iter().position(|id| id == *b_id);
+ a_pos.cmp(&b_pos)
});
-
for (z_index, (kind, pane)) in floating_panes.iter_mut().enumerate() {
let mut active_panes = active_panes.clone();
let multiple_users_exist_in_session =
@@ -806,6 +798,16 @@ impl FloatingPanes {
pane_geom.adjust_coordinates(new_coordinates, viewport);
pane.set_geom(pane_geom);
pane.set_should_render(true);
+
+ // we do this in case this moves the pane under another pane so that the pane user's
+ // are focused on will always be on top
+ let is_focused = self.active_panes.pane_id_is_focused(&pane_id);
+ if is_focused {
+ self.z_indices.retain(|p_id| *p_id != pane_id);
+ self.z_indices.push(pane_id);
+ self.make_sure_pinned_panes_are_on_top();
+ }
+
self.desired_pane_positions.insert(pane_id, pane_geom);
}
let _ = self.set_pane_frames();
@@ -840,7 +842,7 @@ impl FloatingPanes {
self.focus_pane(next_active_pane_id, client_id);
},
None => {
- self.defocus_pane(pane_id, client_id);
+ self.defocus_pane(client_id);
},
}
}
@@ -855,6 +857,7 @@ impl FloatingPanes {
}
self.z_indices.retain(|p_id| *p_id != pane_id);
self.z_indices.push(pane_id);
+ self.make_sure_pinned_panes_are_on_top();
self.set_pane_active_at(pane_id);
self.set_force_render();
}
@@ -888,8 +891,7 @@ impl FloatingPanes {
},
}
}
- pub fn defocus_pane(&mut self, pane_id: PaneId, client_id: ClientId) {
- self.z_indices.retain(|p_id| *p_id != pane_id);
+ pub fn defocus_pane(&mut self, client_id: ClientId) {
self.active_panes.remove(&client_id, &mut self.panes);
self.set_force_render();
}
@@ -1244,4 +1246,27 @@ impl FloatingPanes {
);
floating_pane_grid.next_selectable_pane_id_to_the_right(&pane_id)
}
+ fn make_sure_pinned_panes_are_on_top(&mut self) {
+ let pinned_status: std::collections::HashMap<_, _> = self
+ .z_indices
+ .iter()
+ .map(|id| (id.clone(), self.pane_id_is_pinned(id)))
+ .collect();
+
+ self.z_indices.sort_by(|a_id, b_id| {
+ let a_is_pinned = pinned_status.get(a_id).copied().unwrap_or(false);
+ let b_is_pinned = pinned_status.get(b_id).copied().unwrap_or(false);
+ match (a_is_pinned, b_is_pinned) {
+ (true, false) => Ordering::Greater,
+ (false, true) => Ordering::Less,
+ _ => Ordering::Equal,
+ }
+ });
+ }
+ fn pane_id_is_pinned(&self, pane_id: &PaneId) -> bool {
+ self.panes
+ .get(pane_id)
+ .map(|p| p.position_and_size().is_pinned)
+ .unwrap_or(false)
+ }
}
diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs
index 0e74a9de..ffad3d84 100644
--- a/zellij-server/src/panes/plugin_pane.rs
+++ b/zellij-server/src/panes/plugin_pane.rs
@@ -90,6 +90,7 @@ pub(crate) struct PluginPane {
character_cell_size: Rc<RefCell<Option<SizeInPixels>>>,
vte_parsers: HashMap<ClientId, vte::Parser>,
grids: HashMap<ClientId, Grid>,
+ cursor_visibility: HashMap<ClientId, Option<(usize, usize)>>,
prev_pane_name: String,
frame: HashMap<ClientId, PaneFrame>,
borderless: bool,
@@ -149,6 +150,7 @@ impl PluginPane {
sixel_image_store,
vte_parsers: HashMap::new(),
grids: HashMap::new(),
+ cursor_visibility: HashMap::new(),
style,
pane_frame_color_override: None,
invoked_with,
@@ -248,8 +250,25 @@ impl Pane for PluginPane {
self.should_render.insert(client_id, true);
}
- fn cursor_coordinates(&self) -> Option<(usize, usize)> {
- None
+ fn cursor_coordinates(&self, client_id: Option<ClientId>) -> Option<(usize, usize)> {
+ let own_content_columns = self.get_content_columns();
+ let own_content_rows = self.get_content_rows();
+ let Offset { top, left, .. } = self.content_offset;
+ if let Some(coordinates) =
+ client_id.and_then(|client_id| self.cursor_visibility.get(&client_id))
+ {
+ coordinates
+ .map(|(x, y)| (x + left, y + top))
+ .and_then(|(x, y)| {
+ if x >= own_content_columns || y >= own_content_rows {
+ None
+ } else {
+ Some((x, y)) // these are 0 indexed
+ }
+ })
+ } else {
+ None
+ }
}
fn adjust_input_to_terminal(
&mut self,
@@ -360,6 +379,10 @@ impl Pane for PluginPane {
fn set_selectable(&mut self, selectable: bool) {
self.selectable = selectable;
}
+ fn show_cursor(&mut self, client_id: ClientId, cursor_position: Option<(usize, usize)>) {
+ self.cursor_visibility.insert(client_id, cursor_position);
+ self.should_render.insert(client_id, true);
+ }
fn request_permissions_from_user(&mut self, permissions: Option<PluginPermission>) {
self.requesting_permissions = permissions;
self.handle_plugin_bytes_for_all_clients(Default::default()); // to trigger the render of
@@ -440,7 +463,7 @@ impl Pane for PluginPane {
let res = match self.frame.get(&client_id) {
// TODO: use and_then or something?
Some(last_frame) => {
- if &frame != last_frame {
+ if &frame != last_frame || is_pinned {
if !self.borderless {
let frame_output = frame.render().with_context(err_context)?;
self.frame.insert(client_id, frame);
diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs
index 1c5667a5..97bf5dcc 100644
--- a/zellij-server/src/panes/terminal_pane.rs
+++ b/zellij-server/src/panes/terminal_pane.rs
@@ -197,7 +197,7 @@ impl Pane for TerminalPane {
self.vte_parser.advance(&mut self.grid, byte);
}
}
- fn cursor_coordinates(&self) -> Option<(usize, usize)> {
+ fn cursor_coordinates(&self, _client_id: Option<ClientId>) -> Option<(usize, usize)> {
// (x, y)
if self.get_content_rows() < 1 || self.get_content_columns() < 1 {
// do not render cursor if there's no room for it
@@ -740,6 +740,14 @@ impl Pane for TerminalPane {
if let Some(notification_end) = self.notification_end.as_mut() {
if let Some(exit_status) = exit_status {
notification_end.set_exit_status(exit_status);
+
+ // Check if unblock condition is met
+ if let Some(condition) = notification_end.unblock_condition() {
+ if condition.is_met(exit_status) {
+ // Condition met - drop the NotificationEnd now to unblock
+ drop(self.notification_end.take());
+ }
+ }
}
}
if is_first_run {
@@ -899,6 +907,13 @@ impl Pane for TerminalPane {
fn update_exit_status(&mut self, exit_status: i32) {
if let Some(notification_end) = self.notification_end.as_mut() {
notification_end.set_exit_status(exit_status);
+ // Check if unblock condition is met
+ if let Some(condition) = notification_end.unblock_condition() {
+ if condition.is_met(exit_status) {
+ // Condition met - drop the NotificationEnd now to unblock
+ drop(self.notification_end.take());
+ }
+ }
}
}
}
@@ -922,7 +937,7 @@ impl TerminalPane {
arrow_fonts: bool,
styled_underlines: bool,
explicitly_disable_keyboard_protocol: bool,
- notification_end: Option<NotificationEnd>,
+ mut notification_end: Option<NotificationEnd>,
) -> TerminalPane {
let initial_pane_title =
initial_pane_title.unwrap_or_else(|| format!("Pane #{}", pane_index));
@@ -940,6 +955,9 @@ impl TerminalPane {
styled_underlines,
explicitly_disable_keyboard_protocol,
);
+ if let Some(notification_end) = notification_end.as_mut() {
+ notification_end.set_affected_pane_id(PaneId::Terminal(pid));
+ }
TerminalPane {
frame: HashMap::new(),
content_offset: Offset::default(),
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index fb73a90d..4df68db4 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -313,6 +313,7 @@ impl TiledPanes {
Ok(new_pane_geom) => {
pane.set_geom(new_pane_geom);
self.panes.insert(pane_id, pane); // TODO: is set_geom the right one?
+ self.expand_pane_in_stack(pane_id);
},
Err(e) => {
log::error!("Failed to add pane to stack: {:?}", e);
@@ -349,7 +350,8 @@ impl TiledPanes {
Ok(new_pane_geom) => {
pane.set_geom(new_pane_geom);
self.panes.insert(pane_id, pane);
- self.set_force_render(); // TODO: why do we need this?
+
+ self.expand_pane_in_stack(pane_id);
return;
},
Err(_e) => {
@@ -447,7 +449,9 @@ impl TiledPanes {
.map(|p| p.is_stacked())
.unwrap_or(false);
if !pane_id_is_stacked {
- let _ = pane_grid.make_pane_stacked(&root_pane_id);
+ if let Err(e) = pane_grid.make_pane_stacked(&root_pane_id) {
+ log::error!("Failed to make pane stacked: {:?}", e);
+ }
}
match pane_grid.make_room_in_stack_of_pane_id_for_pane(&root_pane_id) {
Ok(new_pane_geom) => {
diff --git a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
index ddb225a4..0c989a9e 100644
--- a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
+++ b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs
@@ -1344,6 +1344,14 @@ impl<'a> TiledPaneGrid<'a> {
let _ = pane_resizer.layout(direction, side_length);
return true;
}
+ } else {
+ // best effort resize - we just remove the pane and relayout everything
+ // this might happen if we are closing a fixed pane
+ self.panes.borrow_mut().remove(&id);
+ let mut pane_resizer = PaneResizer::new(self.panes.clone());
+ let _ = pane_resizer.layout(SplitDirection::Horizontal, self.display_area.cols);
+ let _ = pane_resizer.layout(SplitDirection::Vertical, self.display_area.rows);
+ return true;
}
false
}
diff --git a/zellij-server/src/panes/tiled_panes/unit/stacked_panes_tests.rs b/zellij-server/src/panes/tiled_panes/unit/stacked_panes_tests.rs
index 6b4edf40..e4adfbe4 100644
--- a/zellij-server/src/panes/tiled_panes/unit/stacked_panes_tests.rs
+++ b/zellij-server/src/panes/tiled_panes/unit/stacked_panes_tests.rs
@@ -1085,7 +1085,7 @@ impl Pane for MockPane {
fn handle_plugin_bytes(&mut self, _client_id: ClientId, _bytes: VteBytes) {
unimplemented!()
}
- fn cursor_coordinates(&self) -> Option<(usize, usize)> {
+ fn cursor_coordinates(&self, _client_id: Option<ClientId>) -> Option<(usize, usize)> {
unimplemented!()
}
diff --git a/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__table_ui_component.snap b/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__table_ui_component.snap
index 7ab7a56c..53059240 100644
--- a/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__table_ui_component.snap
+++ b/zellij-server/src/panes/unit/snapshots/zellij_server__panes__grid__grid_tests__table_ui_component.snap
@@ -2,13 +2,13 @@
source: zellij-server/src/panes/./unit/grid_tests.rs
expression: "format!(\"{:?}\", grid)"
---
-00 (C): title1 title2 title3 title4 title5
-01 (C): 1lksdjflksdjf lkjdsflksjdf lkjsdlkfjsfd lkjsdlkjfd lkjdslkjsdf
-02 (C): 2lksdjflksdjf lkjdsflksjdf lkj😳😳sdlkfjsfd lkjsdlkjfd lkjdslkjsdf
-03 (C): 3lksdjflksdjf lkjdsflksjdf lkjsd😳lkfjsfd lkjsdlkjfd lkjdslkjsdf
-04 (C): 4lksdjflks222djf lk😳222jdsflksjdf lk222jsdlkfjsfd lkwwwjsdlkjfd lkjdslkjsdf
-05 (C): 5lksdjflksdjf lkjdsflksjdf lkjsdlkfjsfd lksdjflksjfdlkjsdlkjfd lkjdrrrrslkjsdf
-06 (C): 6lksdjflk😳sdjf l😳kjdsflksjdf lkjsdlkfjsfd lkjsdlkjfd lwwkwkjdslkjsdf
+00 (C): title1 title2 title3 title4 title5
+01 (C): 1lksdjflksdjf lkjdsflksjdf lkjsdlkfjsfd lkjsdlkjfd lkjdslkjsdf
+02 (C): 2lksdjflksdjf lkjdsflksjdf lkj😳😳sdlkfjsfd lkjsdlkjfd lkjdslkjsdf
+03 (C): 3lksdjflksdjf lkjdsflksjdf lkjsd😳lkfjsfd lkjsdlkjfd lkjdslkjsdf
+04 (C): 4lksdjflks222djf lk😳222jdsflksjdf lk222jsdlkfjsfd lkwwwjsdlkjfd lkjdslkjsdf
+05 (C): 5lksdjflksdjf lkjdsflksjdf lkjsdlkfjsfd lksdjflksjfdlkjsdlkjfd lkjdrrrrslkjsdf
+06 (C): 6lksdjflk😳sdjf l😳kjdsflksjdf lkjsdlkfjsfd lkjsdlkjfd lwwkwkjdslkjsdf
07 (C):
08 (C):
09 (C):