aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/event.rs
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/event.rs
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/event.rs')
-rw-r--r--zellij-utils/src/plugin_api/event.rs62
1 files changed, 62 insertions, 0 deletions
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,
})
}
}