diff options
| author | Aram Drevekenin <aram@poor.dev> | 2024-10-22 15:27:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-22 15:27:40 +0200 |
| commit | d671ab650e231d353a05a2808c0984e952de38c4 (patch) | |
| tree | 38a0604f9b4b20adfed5cf3e8324c59fbdf1ff2b /zellij-utils/src/plugin_api/event.rs | |
| parent | docs(changelog): wasmtime patch upgrade (diff) | |
| download | sl0ppij-d671ab650e231d353a05a2808c0984e952de38c4.tar.gz sl0ppij-d671ab650e231d353a05a2808c0984e952de38c4.tar.xz sl0ppij-d671ab650e231d353a05a2808c0984e952de38c4.zip | |
feat(plugins): add API to list clients, their focused panes and running commands/plugins (#3687)
* fix(list-clients): properly show client info after a tab was closed
* feat(plugins): add API to list clients, their focused panes and running commands/plugins
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src/plugin_api/event.rs')
| -rw-r--r-- | zellij-utils/src/plugin_api/event.rs | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index d1e2f50d..d78f5567 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -1,14 +1,15 @@ pub use super::generated_api::api::{ action::{Action as ProtobufAction, Position as ProtobufPosition}, event::{ - event::Payload as ProtobufEventPayload, CopyDestination as ProtobufCopyDestination, - Event as ProtobufEvent, EventNameList as ProtobufEventNameList, - EventType as ProtobufEventType, FileMetadata as ProtobufFileMetadata, - InputModeKeybinds as ProtobufInputModeKeybinds, KeyBind as ProtobufKeyBind, - LayoutInfo as ProtobufLayoutInfo, ModeUpdatePayload as ProtobufModeUpdatePayload, - PaneId as ProtobufPaneId, PaneInfo as ProtobufPaneInfo, - PaneManifest as ProtobufPaneManifest, PaneType as ProtobufPaneType, - PluginInfo as ProtobufPluginInfo, ResurrectableSession as ProtobufResurrectableSession, + event::Payload as ProtobufEventPayload, ClientInfo as ProtobufClientInfo, + CopyDestination as ProtobufCopyDestination, Event as ProtobufEvent, + EventNameList as ProtobufEventNameList, EventType as ProtobufEventType, + FileMetadata as ProtobufFileMetadata, InputModeKeybinds as ProtobufInputModeKeybinds, + KeyBind as ProtobufKeyBind, LayoutInfo as ProtobufLayoutInfo, + ModeUpdatePayload as ProtobufModeUpdatePayload, PaneId as ProtobufPaneId, + PaneInfo as ProtobufPaneInfo, PaneManifest as ProtobufPaneManifest, + PaneType as ProtobufPaneType, PluginInfo as ProtobufPluginInfo, + ResurrectableSession as ProtobufResurrectableSession, SessionManifest as ProtobufSessionManifest, TabInfo as ProtobufTabInfo, *, }, input_mode::InputMode as ProtobufInputMode, @@ -17,9 +18,9 @@ pub use super::generated_api::api::{ }; #[allow(hidden_glob_reexports)] use crate::data::{ - CopyDestination, Event, EventType, FileMetadata, InputMode, KeyWithModifier, LayoutInfo, - ModeInfo, Mouse, PaneId, PaneInfo, PaneManifest, PermissionStatus, PluginCapabilities, - PluginInfo, SessionInfo, Style, TabInfo, + ClientInfo, CopyDestination, Event, EventType, FileMetadata, InputMode, KeyWithModifier, + LayoutInfo, ModeInfo, Mouse, PaneId, PaneInfo, PaneManifest, PermissionStatus, + PluginCapabilities, PluginInfo, SessionInfo, Style, TabInfo, }; use crate::errors::prelude::*; @@ -320,11 +321,50 @@ impl TryFrom<ProtobufEvent> for Event { )), _ => Err("Malformed payload for the FailedToWriteConfigToDisk Event"), }, + Some(ProtobufEventType::ListClients) => match protobuf_event.payload { + Some(ProtobufEventPayload::ListClientsPayload(mut list_clients_payload)) => { + Ok(Event::ListClients( + list_clients_payload + .client_info + .drain(..) + .filter_map(|c| c.try_into().ok()) + .collect(), + )) + }, + _ => Err("Malformed payload for the FailedToWriteConfigToDisk Event"), + }, None => Err("Unknown Protobuf Event"), } } } +impl TryFrom<ProtobufClientInfo> for ClientInfo { + type Error = &'static str; + fn try_from(protobuf_client_info: ProtobufClientInfo) -> Result<Self, &'static str> { + Ok(ClientInfo::new( + protobuf_client_info.client_id as u16, + protobuf_client_info + .pane_id + .ok_or("No pane id found")? + .try_into()?, + protobuf_client_info.running_command, + protobuf_client_info.is_current_client, + )) + } +} + +impl TryFrom<ClientInfo> for ProtobufClientInfo { + type Error = &'static str; + fn try_from(client_info: ClientInfo) -> Result<Self, &'static str> { + Ok(ProtobufClientInfo { + client_id: client_info.client_id as u32, + pane_id: Some(client_info.pane_id.try_into()?), + running_command: client_info.running_command, + is_current_client: client_info.is_current_client, + }) + } +} + impl TryFrom<Event> for ProtobufEvent { type Error = &'static str; fn try_from(event: Event) -> Result<Self, &'static str> { @@ -634,6 +674,15 @@ impl TryFrom<Event> for ProtobufEvent { FailedToWriteConfigToDiskPayload { file_path }, )), }), + Event::ListClients(mut client_info_list) => Ok(ProtobufEvent { + name: ProtobufEventType::ListClients as i32, + payload: Some(event::Payload::ListClientsPayload(ListClientsPayload { + client_info: client_info_list + .drain(..) + .filter_map(|c| c.try_into().ok()) + .collect(), + })), + }), } } } @@ -1178,6 +1227,7 @@ impl TryFrom<ProtobufEventType> for EventType { ProtobufEventType::EditPaneExited => EventType::EditPaneExited, ProtobufEventType::CommandPaneReRun => EventType::CommandPaneReRun, ProtobufEventType::FailedToWriteConfigToDisk => EventType::FailedToWriteConfigToDisk, + ProtobufEventType::ListClients => EventType::ListClients, }) } } @@ -1212,6 +1262,7 @@ impl TryFrom<EventType> for ProtobufEventType { EventType::EditPaneExited => ProtobufEventType::EditPaneExited, EventType::CommandPaneReRun => ProtobufEventType::CommandPaneReRun, EventType::FailedToWriteConfigToDisk => ProtobufEventType::FailedToWriteConfigToDisk, + EventType::ListClients => ProtobufEventType::ListClients, }) } } |
