aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-12-31 12:37:23 +0100
committerGitHub <noreply@github.com>2024-12-31 12:37:23 +0100
commit42adc8cd048c03d52a9f33503d75e24364adbc68 (patch)
tree943ee11e188e6512b336b603bdd5ea8eae38998b /zellij-utils/src
parentdocs(changelog): cursor overflow fix (diff)
downloadsl0ppij-42adc8cd048c03d52a9f33503d75e24364adbc68.tar.gz
sl0ppij-42adc8cd048c03d52a9f33503d75e24364adbc68.tar.xz
sl0ppij-42adc8cd048c03d52a9f33503d75e24364adbc68.zip
feat(ux): stack panes command (#3905)
* working across tabs and floating panes through the cli * finalize cli command * plugin api * style(fmt): rustfmt * fix: re-focus pane in stack if it was focused * style(fmt): rustfmt * remove outdated comment
Diffstat (limited to 'zellij-utils/src')
-rw-r--r--zellij-utils/src/cli.rs11
-rw-r--r--zellij-utils/src/data.rs1
-rw-r--r--zellij-utils/src/errors.rs1
-rw-r--r--zellij-utils/src/input/actions.rs50
-rw-r--r--zellij-utils/src/plugin_api/action.rs1
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.proto6
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs28
7 files changed, 94 insertions, 4 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 1577be7c..38d51f6d 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -760,4 +760,15 @@ tail -f /tmp/my-live-logfile | zellij action pipe --name logs --plugin https://e
},
ListClients,
TogglePanePinned,
+ /// Stack pane ids
+ /// Ids are a space separated list of pane ids.
+ /// They should either be in the form of `terminal_<int>` (eg. terminal_1), `plugin_<int>` (eg.
+ /// plugin_1) or bare integers in which case they'll be considered terminals (eg. 1 is
+ /// the equivalent of terminal_1)
+ ///
+ /// Example: zellij action stack-panes -- terminal_1 plugin_2 3
+ StackPanes {
+ #[clap(last(true), required(true))]
+ pane_ids: Vec<String>,
+ },
}
diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs
index 1f3adf30..de14de02 100644
--- a/zellij-utils/src/data.rs
+++ b/zellij-utils/src/data.rs
@@ -1902,4 +1902,5 @@ pub enum PluginCommand {
ListClients,
ChangeHostFolder(PathBuf),
SetFloatingPanePinned(PaneId, bool), // bool -> should be pinned
+ StackPanes(Vec<PaneId>),
}
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs
index f27ee06c..bd82b61c 100644
--- a/zellij-utils/src/errors.rs
+++ b/zellij-utils/src/errors.rs
@@ -375,6 +375,7 @@ pub enum ScreenContext {
ListClientsToPlugin,
TogglePanePinned,
SetFloatingPanePinned,
+ StackPanes,
}
/// Stack call representations corresponding to the different types of [`PtyInstruction`]s.
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index f6ecf096..95ec6eb2 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -6,7 +6,7 @@ use super::layout::{
SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
};
use crate::cli::CliAction;
-use crate::data::{Direction, KeyWithModifier, Resize};
+use crate::data::{Direction, KeyWithModifier, PaneId, Resize};
use crate::data::{FloatingPaneCoordinates, InputMode};
use crate::home::{find_default_config_dir, get_layout_dir};
use crate::input::config::{Config, ConfigError, KdlError};
@@ -301,6 +301,7 @@ pub enum Action {
},
ListClients,
TogglePanePinned,
+ StackPanes(Vec<PaneId>),
}
impl Action {
@@ -742,6 +743,53 @@ impl Action {
},
CliAction::ListClients => Ok(vec![Action::ListClients]),
CliAction::TogglePanePinned => Ok(vec![Action::TogglePanePinned]),
+ CliAction::StackPanes { pane_ids } => {
+ let mut malformed_ids = vec![];
+ let pane_ids = pane_ids
+ .iter()
+ .filter_map(|stringified_pane_id| {
+ if let Some(terminal_pane_id) =
+ stringified_pane_id.strip_prefix("terminal_")
+ {
+ u32::from_str_radix(terminal_pane_id, 10)
+ .ok()
+ .or_else(|| {
+ malformed_ids.push(stringified_pane_id.to_owned());
+ None
+ })
+ .map(|id| PaneId::Terminal(id))
+ } else if let Some(plugin_pane_id) =
+ stringified_pane_id.strip_prefix("plugin_")
+ {
+ u32::from_str_radix(plugin_pane_id, 10)
+ .ok()
+ .or_else(|| {
+ malformed_ids.push(stringified_pane_id.to_owned());
+ None
+ })
+ .map(|id| PaneId::Plugin(id))
+ } else {
+ u32::from_str_radix(stringified_pane_id, 10)
+ .ok()
+ .or_else(|| {
+ malformed_ids.push(stringified_pane_id.to_owned());
+ None
+ })
+ .map(|id| PaneId::Terminal(id))
+ }
+ })
+ .collect();
+ if !malformed_ids.is_empty() {
+ Err(
+ format!(
+ "Malformed pane ids: {}, expecting a space separated list of either a bare integer (eg. 1), a terminal pane id (eg. terminal_1) or a plugin pane id (eg. plugin_1)",
+ malformed_ids.join(", ")
+ )
+ )
+ } else {
+ Ok(vec![Action::StackPanes(pane_ids)])
+ }
+ },
}
}
pub fn launches_plugin(&self, plugin_url: &str) -> bool {
diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs
index 96385433..e3c05130 100644
--- a/zellij-utils/src/plugin_api/action.rs
+++ b/zellij-utils/src/plugin_api/action.rs
@@ -1301,6 +1301,7 @@ impl TryFrom<Action> for ProtobufAction {
| Action::DumpLayout
| Action::CliPipe { .. }
| Action::ListClients
+ | Action::StackPanes(..)
| Action::SkipConfirm(..) => Err("Unsupported action"),
}
}
diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto
index 14e8a286..7572476d 100644
--- a/zellij-utils/src/plugin_api/plugin_command.proto
+++ b/zellij-utils/src/plugin_api/plugin_command.proto
@@ -129,6 +129,7 @@ enum CommandName {
ListClients = 113;
ChangeHostFolder = 114;
SetFloatingPanePinned = 115;
+ StackPanes = 116;
}
message PluginCommand {
@@ -214,9 +215,14 @@ message PluginCommand {
RebindKeysPayload rebind_keys_payload = 88;
ChangeHostFolderPayload change_host_folder_payload = 89;
SetFloatingPanePinnedPayload set_floating_pane_pinned_payload = 90;
+ StackPanesPayload stack_panes_payload = 91;
}
}
+message StackPanesPayload {
+ repeated PaneId pane_ids = 1;
+}
+
message SetFloatingPanePinnedPayload {
PaneId pane_id = 1;
bool should_be_pinned = 2;
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index 9d92f260..2621502a 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -19,9 +19,10 @@ pub use super::generated_api::api::{
RerunCommandPanePayload, ResizePaneIdWithDirectionPayload, ResizePayload,
RunCommandPayload, ScrollDownInPaneIdPayload, ScrollToBottomInPaneIdPayload,
ScrollToTopInPaneIdPayload, ScrollUpInPaneIdPayload, SetFloatingPanePinnedPayload,
- SetTimeoutPayload, ShowPaneWithIdPayload, SubscribePayload, SwitchSessionPayload,
- SwitchTabToPayload, TogglePaneEmbedOrEjectForPaneIdPayload, TogglePaneIdFullscreenPayload,
- UnsubscribePayload, WebRequestPayload, WriteCharsToPaneIdPayload, WriteToPaneIdPayload,
+ SetTimeoutPayload, ShowPaneWithIdPayload, StackPanesPayload, SubscribePayload,
+ SwitchSessionPayload, SwitchTabToPayload, TogglePaneEmbedOrEjectForPaneIdPayload,
+ TogglePaneIdFullscreenPayload, UnsubscribePayload, WebRequestPayload,
+ WriteCharsToPaneIdPayload, WriteToPaneIdPayload,
},
plugin_permission::PermissionType as ProtobufPermissionType,
resize::ResizeAction as ProtobufResizeAction,
@@ -1328,6 +1329,18 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
_ => Err("Mismatched payload for SetFloatingPanePinned"),
},
+ Some(CommandName::StackPanes) => match protobuf_plugin_command.payload {
+ Some(Payload::StackPanesPayload(stack_panes_payload)) => {
+ Ok(PluginCommand::StackPanes(
+ stack_panes_payload
+ .pane_ids
+ .into_iter()
+ .filter_map(|p_id| p_id.try_into().ok())
+ .collect(),
+ ))
+ },
+ _ => Err("Mismatched payload for SetFloatingPanePinned"),
+ },
None => Err("Unrecognized plugin command"),
}
}
@@ -2172,6 +2185,15 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
)),
})
},
+ PluginCommand::StackPanes(pane_ids) => Ok(ProtobufPluginCommand {
+ name: CommandName::StackPanes as i32,
+ payload: Some(Payload::StackPanesPayload(StackPanesPayload {
+ pane_ids: pane_ids
+ .into_iter()
+ .filter_map(|p_id| p_id.try_into().ok())
+ .collect(),
+ })),
+ }),
}
}
}