aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-10-22 15:27:40 +0200
committerGitHub <noreply@github.com>2024-10-22 15:27:40 +0200
commitd671ab650e231d353a05a2808c0984e952de38c4 (patch)
tree38a0604f9b4b20adfed5cf3e8324c59fbdf1ff2b /zellij-utils/src/plugin_api
parentdocs(changelog): wasmtime patch upgrade (diff)
downloadsl0ppij-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')
-rw-r--r--zellij-utils/src/plugin_api/event.proto13
-rw-r--r--zellij-utils/src/plugin_api/event.rs73
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.proto1
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs8
4 files changed, 84 insertions, 11 deletions
diff --git a/zellij-utils/src/plugin_api/event.proto b/zellij-utils/src/plugin_api/event.proto
index e3f3cacb..607ba448 100644
--- a/zellij-utils/src/plugin_api/event.proto
+++ b/zellij-utils/src/plugin_api/event.proto
@@ -49,6 +49,7 @@ enum EventType {
EditPaneExited = 23;
CommandPaneReRun = 24;
FailedToWriteConfigToDisk = 25;
+ ListClients = 26;
}
message EventNameList {
@@ -79,9 +80,21 @@ message Event {
EditPaneExitedPayload edit_pane_exited_payload = 20;
CommandPaneReRunPayload command_pane_rerun_payload = 21;
FailedToWriteConfigToDiskPayload failed_to_write_config_to_disk_payload = 22;
+ ListClientsPayload list_clients_payload = 23;
}
}
+message ListClientsPayload {
+ repeated ClientInfo client_info = 1;
+}
+
+message ClientInfo {
+ uint32 client_id = 1;
+ PaneId pane_id = 2;
+ string running_command = 3;
+ bool is_current_client = 4;
+}
+
message FailedToWriteConfigToDiskPayload {
optional string file_path = 1;
}
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,
})
}
}
diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto
index 29ebca67..5b58de14 100644
--- a/zellij-utils/src/plugin_api/plugin_command.proto
+++ b/zellij-utils/src/plugin_api/plugin_command.proto
@@ -126,6 +126,7 @@ enum CommandName {
ReloadPlugin = 110;
LoadNewPlugin = 111;
RebindKeys = 112;
+ ListClients = 113;
}
message PluginCommand {
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index 79b08794..06687971 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -1299,6 +1299,10 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
},
_ => Err("Mismatched payload for RebindKeys"),
},
+ Some(CommandName::ListClients) => match protobuf_plugin_command.payload {
+ Some(_) => Err("ListClients should have no payload, found a payload"),
+ None => Ok(PluginCommand::ListClients),
+ },
None => Err("Unrecognized plugin command"),
}
}
@@ -2122,6 +2126,10 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
write_config_to_disk,
})),
}),
+ PluginCommand::ListClients => Ok(ProtobufPluginCommand {
+ name: CommandName::ListClients as i32,
+ payload: None,
+ }),
}
}
}