aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-07-22 18:30:18 +0200
committerGitHub <noreply@github.com>2024-07-22 18:30:18 +0200
commitffbdb095ec5402455ac7f1cc8ef2f1bb8ebc8df2 (patch)
tree99467c7156aa1b9c2fa6d0b65464e1b0c948c913 /zellij-utils/src/plugin_api
parentdocs(changelog): current process refresh fix (diff)
downloadsl0ppij-ffbdb095ec5402455ac7f1cc8ef2f1bb8ebc8df2.tar.gz
sl0ppij-ffbdb095ec5402455ac7f1cc8ef2f1bb8ebc8df2.tar.xz
sl0ppij-ffbdb095ec5402455ac7f1cc8ef2f1bb8ebc8df2.zip
feat(plugins): some APIs for controlling and receiving information about other panes (#3515)
* add context to opening command panes, and events for their start/finish * show/hide other panes plugin apis * get tests to pass * style(fmt): rustfmt * update plugin test snapshots
Diffstat (limited to 'zellij-utils/src/plugin_api')
-rw-r--r--zellij-utils/src/plugin_api/action.rs1
-rw-r--r--zellij-utils/src/plugin_api/event.proto15
-rw-r--r--zellij-utils/src/plugin_api/event.rs62
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.proto14
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs146
5 files changed, 208 insertions, 30 deletions
diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs
index d148541e..b206dba0 100644
--- a/zellij-utils/src/plugin_api/action.rs
+++ b/zellij-utils/src/plugin_api/action.rs
@@ -1385,6 +1385,7 @@ impl TryFrom<ProtobufRunCommandAction> for RunCommandAction {
direction,
hold_on_close,
hold_on_start,
+ ..Default::default()
})
}
}
diff --git a/zellij-utils/src/plugin_api/event.proto b/zellij-utils/src/plugin_api/event.proto
index c48030aa..ac1bdd29 100644
--- a/zellij-utils/src/plugin_api/event.proto
+++ b/zellij-utils/src/plugin_api/event.proto
@@ -42,6 +42,8 @@ enum EventType {
SessionUpdate = 16;
RunCommandResult = 17;
WebRequestResult = 18;
+ CommandPaneOpened = 19;
+ CommandPaneExited = 20;
}
message EventNameList {
@@ -65,9 +67,22 @@ message Event {
SessionUpdatePayload session_update_payload = 13;
RunCommandResultPayload run_command_result_payload = 14;
WebRequestResultPayload web_request_result_payload = 15;
+ CommandPaneOpenedPayload command_pane_opened_payload = 16;
+ CommandPaneExitedPayload command_pane_exited_payload = 17;
}
}
+message CommandPaneOpenedPayload {
+ uint32 terminal_pane_id = 1;
+ repeated ContextItem context = 2;
+}
+
+message CommandPaneExitedPayload {
+ uint32 terminal_pane_id = 1;
+ optional int32 exit_code = 2;
+ repeated ContextItem context = 3;
+}
+
message SessionUpdatePayload {
repeated SessionManifest session_manifests = 1;
repeated ResurrectableSession resurrectable_sessions = 2;
diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs
index 7996801c..c10c6ec0 100644
--- a/zellij-utils/src/plugin_api/event.rs
+++ b/zellij-utils/src/plugin_api/event.rs
@@ -235,6 +235,33 @@ impl TryFrom<ProtobufEvent> for Event {
},
_ => Err("Malformed payload for the WebRequestResult Event"),
},
+ Some(ProtobufEventType::CommandPaneOpened) => match protobuf_event.payload {
+ Some(ProtobufEventPayload::CommandPaneOpenedPayload(
+ command_pane_opened_payload,
+ )) => Ok(Event::CommandPaneOpened(
+ command_pane_opened_payload.terminal_pane_id,
+ command_pane_opened_payload
+ .context
+ .into_iter()
+ .map(|c_i| (c_i.name, c_i.value))
+ .collect(),
+ )),
+ _ => Err("Malformed payload for the CommandPaneOpened Event"),
+ },
+ Some(ProtobufEventType::CommandPaneExited) => match protobuf_event.payload {
+ Some(ProtobufEventPayload::CommandPaneExitedPayload(
+ command_pane_exited_payload,
+ )) => Ok(Event::CommandPaneExited(
+ command_pane_exited_payload.terminal_pane_id,
+ command_pane_exited_payload.exit_code,
+ command_pane_exited_payload
+ .context
+ .into_iter()
+ .map(|c_i| (c_i.name, c_i.value))
+ .collect(),
+ )),
+ _ => Err("Malformed payload for the CommandPaneExited Event"),
+ },
None => Err("Unknown Protobuf Event"),
}
}
@@ -460,6 +487,37 @@ impl TryFrom<Event> for ProtobufEvent {
)),
})
},
+ Event::CommandPaneOpened(terminal_pane_id, context) => {
+ let command_pane_opened_payload = CommandPaneOpenedPayload {
+ terminal_pane_id,
+ context: context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect(),
+ };
+ Ok(ProtobufEvent {
+ name: ProtobufEventType::CommandPaneOpened as i32,
+ payload: Some(event::Payload::CommandPaneOpenedPayload(
+ command_pane_opened_payload,
+ )),
+ })
+ },
+ Event::CommandPaneExited(terminal_pane_id, exit_code, context) => {
+ let command_pane_exited_payload = CommandPaneExitedPayload {
+ terminal_pane_id,
+ exit_code,
+ context: context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect(),
+ };
+ Ok(ProtobufEvent {
+ name: ProtobufEventType::CommandPaneExited as i32,
+ payload: Some(event::Payload::CommandPaneExitedPayload(
+ command_pane_exited_payload,
+ )),
+ })
+ },
}
}
}
@@ -963,6 +1021,8 @@ impl TryFrom<ProtobufEventType> for EventType {
ProtobufEventType::SessionUpdate => EventType::SessionUpdate,
ProtobufEventType::RunCommandResult => EventType::RunCommandResult,
ProtobufEventType::WebRequestResult => EventType::WebRequestResult,
+ ProtobufEventType::CommandPaneOpened => EventType::CommandPaneOpened,
+ ProtobufEventType::CommandPaneExited => EventType::CommandPaneExited,
})
}
}
@@ -990,6 +1050,8 @@ impl TryFrom<EventType> for ProtobufEventType {
EventType::SessionUpdate => ProtobufEventType::SessionUpdate,
EventType::RunCommandResult => ProtobufEventType::RunCommandResult,
EventType::WebRequestResult => ProtobufEventType::WebRequestResult,
+ EventType::CommandPaneOpened => ProtobufEventType::CommandPaneOpened,
+ EventType::CommandPaneExited => ProtobufEventType::CommandPaneExited,
})
}
}
diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto
index 5442909e..3e3567dd 100644
--- a/zellij-utils/src/plugin_api/plugin_command.proto
+++ b/zellij-utils/src/plugin_api/plugin_command.proto
@@ -99,6 +99,8 @@ enum CommandName {
CloseSelf = 85;
NewTabsWithLayoutInfo = 86;
Reconfigure = 87;
+ HidePaneWithId = 88;
+ ShowPaneWithId = 89;
}
message PluginCommand {
@@ -157,9 +159,20 @@ message PluginCommand {
string scan_host_folder_payload = 61;
NewTabsWithLayoutInfoPayload new_tabs_with_layout_info_payload = 62;
string reconfigure_payload = 63;
+ HidePaneWithIdPayload hide_pane_with_id_payload = 64;
+ ShowPaneWithIdPayload show_pane_with_id_payload = 65;
}
}
+message HidePaneWithIdPayload {
+ PaneId pane_id = 1;
+}
+
+message ShowPaneWithIdPayload {
+ PaneId pane_id = 1;
+ bool should_float_if_hidden = 2;
+}
+
message NewTabsWithLayoutInfoPayload {
event.LayoutInfo layout_info = 1;
}
@@ -230,6 +243,7 @@ message OpenFilePayload {
message OpenCommandPanePayload {
command.Command command_to_run = 1;
optional FloatingPaneCoordinates floating_pane_coordinates = 2;
+ repeated ContextItem context = 3;
}
message SwitchTabToPayload {
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index a6514b1b..e72001e2 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -6,14 +6,14 @@ pub use super::generated_api::api::{
plugin_command::Payload, CliPipeOutputPayload, CommandName, ContextItem, EnvVariable,
ExecCmdPayload, FixedOrPercent as ProtobufFixedOrPercent,
FixedOrPercentValue as ProtobufFixedOrPercentValue,
- FloatingPaneCoordinates as ProtobufFloatingPaneCoordinates, HttpVerb as ProtobufHttpVerb,
- IdAndNewName, KillSessionsPayload, MessageToPluginPayload, MovePayload,
- NewPluginArgs as ProtobufNewPluginArgs, NewTabsWithLayoutInfoPayload,
+ FloatingPaneCoordinates as ProtobufFloatingPaneCoordinates, HidePaneWithIdPayload,
+ HttpVerb as ProtobufHttpVerb, IdAndNewName, KillSessionsPayload, MessageToPluginPayload,
+ MovePayload, NewPluginArgs as ProtobufNewPluginArgs, NewTabsWithLayoutInfoPayload,
OpenCommandPanePayload, OpenFilePayload, PaneId as ProtobufPaneId,
PaneType as ProtobufPaneType, PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
RequestPluginPermissionPayload, ResizePayload, RunCommandPayload, SetTimeoutPayload,
- SubscribePayload, SwitchSessionPayload, SwitchTabToPayload, UnsubscribePayload,
- WebRequestPayload,
+ ShowPaneWithIdPayload, SubscribePayload, SwitchSessionPayload, SwitchTabToPayload,
+ UnsubscribePayload, WebRequestPayload,
},
plugin_permission::PermissionType as ProtobufPermissionType,
resize::ResizeAction as ProtobufResizeAction,
@@ -278,7 +278,15 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
Some(Payload::OpenCommandPanePayload(command_to_run_payload)) => {
match command_to_run_payload.command_to_run {
Some(command_to_run) => {
- Ok(PluginCommand::OpenCommandPane(command_to_run.try_into()?))
+ let context: BTreeMap<String, String> = command_to_run_payload
+ .context
+ .into_iter()
+ .map(|e| (e.name, e.value))
+ .collect();
+ Ok(PluginCommand::OpenCommandPane(
+ command_to_run.try_into()?,
+ context,
+ ))
},
None => Err("Malformed open open command pane payload"),
}
@@ -291,10 +299,18 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
.floating_pane_coordinates
.map(|f| f.into());
match command_to_run_payload.command_to_run {
- Some(command_to_run) => Ok(PluginCommand::OpenCommandPaneFloating(
- command_to_run.try_into()?,
- floating_pane_coordinates,
- )),
+ Some(command_to_run) => {
+ let context: BTreeMap<String, String> = command_to_run_payload
+ .context
+ .into_iter()
+ .map(|e| (e.name, e.value))
+ .collect();
+ Ok(PluginCommand::OpenCommandPaneFloating(
+ command_to_run.try_into()?,
+ floating_pane_coordinates,
+ context,
+ ))
+ },
None => Err("Malformed open command pane floating payload"),
}
},
@@ -719,9 +735,17 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
Some(CommandName::OpenCommandInPlace) => match protobuf_plugin_command.payload {
Some(Payload::OpenCommandPaneInPlacePayload(command_to_run_payload)) => {
match command_to_run_payload.command_to_run {
- Some(command_to_run) => Ok(PluginCommand::OpenCommandPaneInPlace(
- command_to_run.try_into()?,
- )),
+ Some(command_to_run) => {
+ let context: BTreeMap<String, String> = command_to_run_payload
+ .context
+ .into_iter()
+ .map(|e| (e.name, e.value))
+ .collect();
+ Ok(PluginCommand::OpenCommandPaneInPlace(
+ command_to_run.try_into()?,
+ context,
+ ))
+ },
None => Err("Malformed open command pane in-place payload"),
}
},
@@ -894,6 +918,30 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
_ => Err("Mismatched payload for Reconfigure"),
},
+ Some(CommandName::HidePaneWithId) => match protobuf_plugin_command.payload {
+ Some(Payload::HidePaneWithIdPayload(hide_pane_with_id_payload)) => {
+ let pane_id = hide_pane_with_id_payload
+ .pane_id
+ .and_then(|p_id| PaneId::try_from(p_id).ok())
+ .ok_or("Failed to parse HidePaneWithId command")?;
+ Ok(PluginCommand::HidePaneWithId(pane_id))
+ },
+ _ => Err("Mismatched payload for HidePaneWithId"),
+ },
+ Some(CommandName::ShowPaneWithId) => match protobuf_plugin_command.payload {
+ Some(Payload::ShowPaneWithIdPayload(show_pane_with_id_payload)) => {
+ let pane_id = show_pane_with_id_payload
+ .pane_id
+ .and_then(|p_id| PaneId::try_from(p_id).ok())
+ .ok_or("Failed to parse ShowPaneWithId command")?;
+ let should_float_if_hidden = show_pane_with_id_payload.should_float_if_hidden;
+ Ok(PluginCommand::ShowPaneWithId(
+ pane_id,
+ should_float_if_hidden,
+ ))
+ },
+ _ => Err("Mismatched payload for ShowPaneWithId"),
+ },
None => Err("Unrecognized plugin command"),
}
}
@@ -965,20 +1013,36 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
})),
})
},
- PluginCommand::OpenCommandPane(command_to_run) => Ok(ProtobufPluginCommand {
- name: CommandName::OpenCommandPane as i32,
- payload: Some(Payload::OpenCommandPanePayload(OpenCommandPanePayload {
- command_to_run: Some(command_to_run.try_into()?),
- floating_pane_coordinates: None,
- })),
- }),
- PluginCommand::OpenCommandPaneFloating(command_to_run, floating_pane_coordinates) => {
+ PluginCommand::OpenCommandPane(command_to_run, context) => {
+ let context: Vec<_> = context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect();
+ Ok(ProtobufPluginCommand {
+ name: CommandName::OpenCommandPane as i32,
+ payload: Some(Payload::OpenCommandPanePayload(OpenCommandPanePayload {
+ command_to_run: Some(command_to_run.try_into()?),
+ floating_pane_coordinates: None,
+ context,
+ })),
+ })
+ },
+ PluginCommand::OpenCommandPaneFloating(
+ command_to_run,
+ floating_pane_coordinates,
+ context,
+ ) => {
+ let context: Vec<_> = context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect();
Ok(ProtobufPluginCommand {
name: CommandName::OpenCommandPaneFloating as i32,
payload: Some(Payload::OpenCommandPaneFloatingPayload(
OpenCommandPanePayload {
command_to_run: Some(command_to_run.try_into()?),
floating_pane_coordinates: floating_pane_coordinates.map(|f| f.into()),
+ context,
},
)),
})
@@ -1277,15 +1341,22 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
floating_pane_coordinates: None,
})),
}),
- PluginCommand::OpenCommandPaneInPlace(command_to_run) => Ok(ProtobufPluginCommand {
- name: CommandName::OpenCommandInPlace as i32,
- payload: Some(Payload::OpenCommandPaneInPlacePayload(
- OpenCommandPanePayload {
- command_to_run: Some(command_to_run.try_into()?),
- floating_pane_coordinates: None,
- },
- )),
- }),
+ PluginCommand::OpenCommandPaneInPlace(command_to_run, context) => {
+ let context: Vec<_> = context
+ .into_iter()
+ .map(|(name, value)| ContextItem { name, value })
+ .collect();
+ Ok(ProtobufPluginCommand {
+ name: CommandName::OpenCommandInPlace as i32,
+ payload: Some(Payload::OpenCommandPaneInPlacePayload(
+ OpenCommandPanePayload {
+ command_to_run: Some(command_to_run.try_into()?),
+ floating_pane_coordinates: None,
+ context,
+ },
+ )),
+ })
+ },
PluginCommand::RunCommand(command_line, env_variables, cwd, context) => {
let env_variables: Vec<_> = env_variables
.into_iter()
@@ -1430,6 +1501,21 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::Reconfigure as i32,
payload: Some(Payload::ReconfigurePayload(reconfigure_payload)),
}),
+ PluginCommand::HidePaneWithId(pane_id_to_hide) => Ok(ProtobufPluginCommand {
+ name: CommandName::HidePaneWithId as i32,
+ payload: Some(Payload::HidePaneWithIdPayload(HidePaneWithIdPayload {
+ pane_id: ProtobufPaneId::try_from(pane_id_to_hide).ok(),
+ })),
+ }),
+ PluginCommand::ShowPaneWithId(pane_id_to_show, should_float_if_hidden) => {
+ Ok(ProtobufPluginCommand {
+ name: CommandName::ShowPaneWithId as i32,
+ payload: Some(Payload::ShowPaneWithIdPayload(ShowPaneWithIdPayload {
+ pane_id: ProtobufPaneId::try_from(pane_id_to_show).ok(),
+ should_float_if_hidden,
+ })),
+ })
+ },
}
}
}