aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input
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-utils/src/input
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-utils/src/input')
-rw-r--r--zellij-utils/src/input/actions.rs169
-rw-r--r--zellij-utils/src/input/command.rs28
-rw-r--r--zellij-utils/src/input/layout.rs38
-rw-r--r--zellij-utils/src/input/mouse.rs6
-rw-r--r--zellij-utils/src/input/plugins.rs1
5 files changed, 237 insertions, 5 deletions
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index d623197b..92d697a9 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -1,12 +1,15 @@
//! Definition of the actions that can be bound to keys.
-use super::command::{OpenFilePayload, RunCommandAction};
+pub use super::command::{OpenFilePayload, RunCommandAction};
use super::layout::{
FloatingPaneLayout, Layout, PluginAlias, RunPlugin, RunPluginLocation, RunPluginOrAlias,
SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
};
use crate::cli::CliAction;
-use crate::data::{Direction, KeyWithModifier, LayoutInfo, NewPanePlacement, PaneId, Resize};
+use crate::data::{
+ CommandOrPlugin, Direction, KeyWithModifier, LayoutInfo, NewPanePlacement, OriginatingPlugin,
+ PaneId, Resize, UnblockCondition,
+};
use crate::data::{FloatingPaneCoordinates, InputMode};
use crate::home::{find_default_config_dir, get_layout_dir};
use crate::input::config::{Config, ConfigError, KdlError};
@@ -99,7 +102,18 @@ impl FromStr for SearchOption {
// They might need to be adjusted in the default config
// as well `../../assets/config/default.yaml`
/// Actions that can be bound to keys.
-#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, strum_macros::Display)]
+#[derive(
+ Clone,
+ Debug,
+ PartialEq,
+ Eq,
+ Deserialize,
+ Serialize,
+ strum_macros::Display,
+ strum_macros::EnumString,
+ strum_macros::EnumIter,
+)]
+#[strum(ascii_case_insensitive)]
pub enum Action {
/// Quit Zellij.
Quit,
@@ -194,6 +208,8 @@ pub enum Action {
placement: NewPanePlacement,
pane_name: Option<String>,
command: Option<RunCommandAction>,
+ unblock_condition: Option<UnblockCondition>,
+ near_current_pane: bool,
},
/// Open the file in a new pane using the default editor
EditFile {
@@ -203,27 +219,34 @@ pub enum Action {
in_place: bool,
start_suppressed: bool,
coordinates: Option<FloatingPaneCoordinates>,
+ near_current_pane: bool,
},
/// Open a new floating pane
NewFloatingPane {
command: Option<RunCommandAction>,
pane_name: Option<String>,
coordinates: Option<FloatingPaneCoordinates>,
+ near_current_pane: bool,
},
/// Open a new tiled (embedded, non-floating) pane
NewTiledPane {
direction: Option<Direction>,
command: Option<RunCommandAction>,
pane_name: Option<String>,
+ near_current_pane: bool,
},
/// Open a new pane in place of the focused one, suppressing it instead
NewInPlacePane {
command: Option<RunCommandAction>,
pane_name: Option<String>,
+ near_current_pane: bool,
+ pane_id_to_replace: Option<PaneId>,
+ close_replace_pane: bool,
},
NewStackedPane {
command: Option<RunCommandAction>,
pane_name: Option<String>,
+ near_current_pane: bool,
},
/// Embed focused pane in tab if floating or float focused pane if embedded
TogglePaneEmbedOrFloating,
@@ -244,6 +267,8 @@ pub enum Action {
tab_name: Option<String>,
should_change_focus_to_new_tab: bool,
cwd: Option<PathBuf>,
+ initial_panes: Option<Vec<CommandOrPlugin>>,
+ first_pane_unblock_condition: Option<UnblockCondition>,
},
/// Do nothing.
NoOp,
@@ -271,6 +296,7 @@ pub enum Action {
/// Run specified command in new pane.
Run {
command: RunCommandAction,
+ near_current_pane: bool,
},
/// Detach session and exit
Detach,
@@ -356,10 +382,12 @@ pub enum Action {
FocusTerminalPaneWithId {
pane_id: u32,
should_float_if_hidden: bool,
+ should_be_in_place_if_hidden: bool,
},
FocusPluginPaneWithId {
pane_id: u32,
should_float_if_hidden: bool,
+ should_be_in_place_if_hidden: bool,
},
RenameTerminalPane {
pane_id: u32,
@@ -420,6 +448,24 @@ pub enum Action {
ToggleGroupMarking,
}
+impl Default for Action {
+ fn default() -> Self {
+ Action::NoOp
+ }
+}
+
+impl Default for SearchDirection {
+ fn default() -> Self {
+ SearchDirection::Down
+ }
+}
+
+impl Default for SearchOption {
+ fn default() -> Self {
+ SearchOption::CaseSensitivity
+ }
+}
+
impl Action {
/// Checks that two Action are match except their mutable attributes.
pub fn shallow_eq(&self, other_action: &Action) -> bool {
@@ -492,6 +538,8 @@ impl Action {
pinned,
stacked,
blocking,
+ unblock_condition,
+ near_current_pane,
} => {
let current_dir = get_current_dir();
// cwd should only be specified in a plugin alias if it was explicitly given to us,
@@ -500,7 +548,7 @@ impl Action {
let cwd = cwd
.map(|cwd| current_dir.join(cwd))
.or_else(|| Some(current_dir.clone()));
- if blocking {
+ if blocking || unblock_condition.is_some() {
// For blocking panes, we don't support plugins
if plugin.is_some() {
return Err("Blocking panes do not support plugin variants".to_string());
@@ -543,6 +591,8 @@ impl Action {
placement,
pane_name: name,
command,
+ unblock_condition,
+ near_current_pane,
}])
} else if let Some(plugin) = plugin {
let plugin = match RunPluginLocation::parse(&plugin, cwd.clone()) {
@@ -614,22 +664,28 @@ impl Action {
command: Some(run_command_action),
pane_name: name,
coordinates: FloatingPaneCoordinates::new(x, y, width, height, pinned),
+ near_current_pane,
}])
} else if in_place {
Ok(vec![Action::NewInPlacePane {
command: Some(run_command_action),
pane_name: name,
+ near_current_pane,
+ pane_id_to_replace: None, // TODO: support this
+ close_replace_pane: false,
}])
} else if stacked {
Ok(vec![Action::NewStackedPane {
command: Some(run_command_action),
pane_name: name,
+ near_current_pane,
}])
} else {
Ok(vec![Action::NewTiledPane {
direction,
command: Some(run_command_action),
pane_name: name,
+ near_current_pane,
}])
}
} else {
@@ -638,22 +694,28 @@ impl Action {
command: None,
pane_name: name,
coordinates: FloatingPaneCoordinates::new(x, y, width, height, pinned),
+ near_current_pane,
}])
} else if in_place {
Ok(vec![Action::NewInPlacePane {
command: None,
pane_name: name,
+ near_current_pane,
+ pane_id_to_replace: None, // TODO: support this
+ close_replace_pane: false,
}])
} else if stacked {
Ok(vec![Action::NewStackedPane {
command: None,
pane_name: name,
+ near_current_pane,
}])
} else {
Ok(vec![Action::NewTiledPane {
direction,
command: None,
pane_name: name,
+ near_current_pane,
}])
}
}
@@ -670,6 +732,7 @@ impl Action {
width,
height,
pinned,
+ near_current_pane,
} => {
let mut file = file;
let current_dir = get_current_dir();
@@ -689,6 +752,7 @@ impl Action {
in_place,
start_suppressed,
coordinates: FloatingPaneCoordinates::new(x, y, width, height, pinned),
+ near_current_pane,
}])
},
CliAction::SwitchMode { input_mode } => Ok(vec![Action::SwitchToMode { input_mode }]),
@@ -721,11 +785,68 @@ impl Action {
layout,
layout_dir,
cwd,
+ initial_command,
+ initial_plugin,
+ close_on_exit,
+ start_suspended,
+ block_until_exit_success,
+ block_until_exit_failure,
+ block_until_exit,
} => {
let current_dir = get_current_dir();
let cwd = cwd
.map(|cwd| current_dir.join(cwd))
- .or_else(|| Some(current_dir));
+ .or_else(|| Some(current_dir.clone()));
+
+ // Map CLI flags to UnblockCondition
+ let first_pane_unblock_condition = if block_until_exit_success {
+ Some(UnblockCondition::OnExitSuccess)
+ } else if block_until_exit_failure {
+ Some(UnblockCondition::OnExitFailure)
+ } else if block_until_exit {
+ Some(UnblockCondition::OnAnyExit)
+ } else {
+ None
+ };
+
+ // Parse initial_panes from initial_command or initial_plugin
+ let initial_panes = if let Some(plugin_url) = initial_plugin {
+ let plugin = match RunPluginLocation::parse(&plugin_url, cwd.clone()) {
+ Ok(location) => RunPluginOrAlias::RunPlugin(RunPlugin {
+ _allow_exec_host_cmd: false,
+ location,
+ configuration: Default::default(),
+ initial_cwd: cwd.clone(),
+ }),
+ Err(_) => {
+ let mut plugin_alias =
+ PluginAlias::new(&plugin_url, &None, cwd.clone());
+ plugin_alias.set_caller_cwd_if_not_set(Some(current_dir.clone()));
+ RunPluginOrAlias::Alias(plugin_alias)
+ },
+ };
+ Some(vec![CommandOrPlugin::Plugin(plugin)])
+ } else if !initial_command.is_empty() {
+ let mut command: Vec<String> = initial_command.clone();
+ let (command, args) = (
+ PathBuf::from(command.remove(0)),
+ command.into_iter().collect(),
+ );
+ let hold_on_close = !close_on_exit;
+ let hold_on_start = start_suspended;
+ let run_command_action = RunCommandAction {
+ command,
+ args,
+ cwd: cwd.clone(),
+ direction: None,
+ hold_on_close,
+ hold_on_start,
+ ..Default::default()
+ };
+ Some(vec![CommandOrPlugin::Command(run_command_action)])
+ } else {
+ None
+ };
if let Some(layout_path) = layout {
let layout_dir = layout_dir
.or_else(|| config.and_then(|c| c.options.layout_dir))
@@ -813,6 +934,8 @@ impl Action {
tab_name: name,
should_change_focus_to_new_tab,
cwd: None, // the cwd is done through the layout
+ initial_panes: initial_panes.clone(),
+ first_pane_unblock_condition,
});
}
Ok(new_tab_actions)
@@ -829,6 +952,8 @@ impl Action {
tab_name: name,
should_change_focus_to_new_tab,
cwd: None, // the cwd is done through the layout
+ initial_panes,
+ first_pane_unblock_condition,
}])
}
} else {
@@ -841,6 +966,8 @@ impl Action {
tab_name: name,
should_change_focus_to_new_tab,
cwd,
+ initial_panes,
+ first_pane_unblock_condition,
}])
}
},
@@ -1047,6 +1174,38 @@ impl Action {
},
}
}
+ pub fn populate_originating_plugin(&mut self, originating_plugin: OriginatingPlugin) {
+ match self {
+ Action::NewBlockingPane { command, .. }
+ | Action::NewFloatingPane { command, .. }
+ | Action::NewTiledPane { command, .. }
+ | Action::NewInPlacePane { command, .. }
+ | Action::NewStackedPane { command, .. } => {
+ command
+ .as_mut()
+ .map(|c| c.populate_originating_plugin(originating_plugin));
+ },
+ Action::Run { command, .. } => {
+ command.populate_originating_plugin(originating_plugin);
+ },
+ Action::EditFile { payload, .. } => {
+ payload.originating_plugin = Some(originating_plugin);
+ },
+ Action::NewTab { initial_panes, .. } => {
+ if let Some(initial_panes) = initial_panes.as_mut() {
+ for pane in initial_panes.iter_mut() {
+ match pane {
+ CommandOrPlugin::Command(run_command) => {
+ run_command.populate_originating_plugin(originating_plugin.clone());
+ },
+ _ => {},
+ }
+ }
+ }
+ },
+ _ => {},
+ }
+ }
pub fn launches_plugin(&self, plugin_url: &str) -> bool {
match self {
Action::LaunchPlugin { plugin, .. } => &plugin.location_string() == plugin_url,
diff --git a/zellij-utils/src/input/command.rs b/zellij-utils/src/input/command.rs
index 0169f799..11a34f59 100644
--- a/zellij-utils/src/input/command.rs
+++ b/zellij-utils/src/input/command.rs
@@ -30,6 +30,17 @@ pub struct OpenFilePayload {
pub originating_plugin: Option<OriginatingPlugin>,
}
+impl Default for OpenFilePayload {
+ fn default() -> Self {
+ OpenFilePayload {
+ path: PathBuf::new(),
+ line_number: None,
+ cwd: None,
+ originating_plugin: None,
+ }
+ }
+}
+
impl OpenFilePayload {
pub fn new(path: PathBuf, line_number: Option<usize>, cwd: Option<PathBuf>) -> Self {
OpenFilePayload {
@@ -129,6 +140,23 @@ impl From<RunCommand> for RunCommandAction {
}
}
+impl RunCommandAction {
+ pub fn new(mut command: Vec<String>) -> Self {
+ if command.is_empty() {
+ Default::default()
+ } else {
+ RunCommandAction {
+ command: PathBuf::from(command.remove(0)),
+ args: command,
+ ..Default::default()
+ }
+ }
+ }
+ pub fn populate_originating_plugin(&mut self, originating_plugin: OriginatingPlugin) {
+ self.originating_plugin = Some(originating_plugin);
+ }
+}
+
impl RunCommand {
pub fn new(command: PathBuf) -> Self {
RunCommand {
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index de555a00..d925f7c5 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -995,6 +995,44 @@ impl TiledPaneLayout {
}
run_instructions
}
+ pub fn replace_next_empty_slot_with_run(&mut self, run_to_insert: Run) -> bool {
+ // Replaces the first empty slot (None or Run::Cwd) with the given Run instruction.
+ // Returns true if a replacement was made, false if no empty slot was found.
+ // Traversal order matches extract_run_instructions (breadth-first).
+
+ if self.children.is_empty() {
+ // This is a leaf node - check if it's an empty slot
+ match &self.run {
+ None | Some(Run::Cwd(_)) => {
+ self.run = Some(run_to_insert);
+ return true;
+ },
+ _ => return false,
+ }
+ }
+
+ // Check first child of each child (breadth-first first level)
+ for child in self.children.iter_mut() {
+ if child.children.is_empty() {
+ match &child.run {
+ None | Some(Run::Cwd(_)) => {
+ child.run = Some(run_to_insert);
+ return true;
+ },
+ _ => {},
+ }
+ }
+ }
+
+ // Recursively check deeper levels (breadth-first continuation)
+ for child in self.children.iter_mut() {
+ if child.replace_next_empty_slot_with_run(run_to_insert.clone()) {
+ return true;
+ }
+ }
+
+ false
+ }
pub fn ignore_run_instruction(&mut self, run_instruction: Option<Run>) {
self.run_instructions_to_ignore.push(run_instruction);
}
diff --git a/zellij-utils/src/input/mouse.rs b/zellij-utils/src/input/mouse.rs
index d920495d..0977d5e7 100644
--- a/zellij-utils/src/input/mouse.rs
+++ b/zellij-utils/src/input/mouse.rs
@@ -239,3 +239,9 @@ impl MouseEvent {
event
}
}
+
+impl Default for MouseEvent {
+ fn default() -> Self {
+ MouseEvent::new()
+ }
+}
diff --git a/zellij-utils/src/input/plugins.rs b/zellij-utils/src/input/plugins.rs
index c4755205..892c7a66 100644
--- a/zellij-utils/src/input/plugins.rs
+++ b/zellij-utils/src/input/plugins.rs
@@ -67,6 +67,7 @@ impl PluginConfig {
|| tag == "about"
|| tag == "share"
|| tag == "multiple-select"
+ || tag == "sequence"
{
Some(PluginConfig {
path: PathBuf::from(&tag),