aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/plugin_command.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-04-17 14:08:48 +0200
committerGitHub <noreply@github.com>2026-04-17 14:08:48 +0200
commitaa29cbaf6631af0afca6aae427a97b3e478393b3 (patch)
tree0ee1cab0f7bdc66cf151f38341252701338c1853 /zellij-utils/src/plugin_api/plugin_command.rs
parentfix(windows): skip modifier re-encoding for Char keys in cast_crossterm_key (... (diff)
downloadsl0ppij-aa29cbaf6631af0afca6aae427a97b3e478393b3.tar.gz
sl0ppij-aa29cbaf6631af0afca6aae427a97b3e478393b3.tar.xz
sl0ppij-aa29cbaf6631af0afca6aae427a97b3e478393b3.zip
Some idle CPU and disk/io fixes, new CommandChanged plugin Event (#5063)
* initial implementation * fix mouse cpu spam * prevent excess metadata write and prune sessions on startup * consolidate CommandChanged and PaneCommandChanged * tests * rustfmt * add pr
Diffstat (limited to 'zellij-utils/src/plugin_api/plugin_command.rs')
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs94
1 files changed, 85 insertions, 9 deletions
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index a457f720..5bfb2b42 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -1,13 +1,17 @@
pub use super::generated_api::api::{
action::{Action as ProtobufAction, PaneIdAndShouldFloat, SwitchToModePayload},
- event::{EventNameList as ProtobufEventNameList, Header},
+ event::{
+ EventNameList as ProtobufEventNameList, Header,
+ ResurrectableSession as ProtobufResurrectableSession,
+ SessionManifest as ProtobufSessionManifest,
+ },
input_mode::InputMode as ProtobufInputMode,
plugin_command::{
break_panes_to_new_tab_response, break_panes_to_tab_with_id_response,
break_panes_to_tab_with_index_response, delete_layout_response, dump_layout_response,
dump_session_layout_response, edit_layout_response, focus_or_create_tab_response,
get_focused_pane_info_response, get_pane_cwd_response, get_pane_pid_response,
- get_pane_running_command_response, hide_floating_panes_response,
+ get_pane_running_command_response, get_session_list_response, hide_floating_panes_response,
highlight_style::Style as ProtobufHighlightStyleVariant, new_tab_response,
parse_layout_response, plugin_command::Payload, rename_layout_response,
save_layout_response, save_session_response, show_floating_panes_response,
@@ -48,7 +52,9 @@ pub use super::generated_api::api::{
GetPaneScrollbackPayload,
GetSessionEnvironmentVariablesPayload as ProtobufGetSessionEnvironmentVariablesPayload,
GetSessionEnvironmentVariablesResponse as ProtobufGetSessionEnvironmentVariablesResponse,
- GetTabInfoPayload, GetTabInfoResponse as ProtobufGetTabInfoResponse, GoToTabWithIdPayload,
+ GetSessionListPayload as ProtobufGetSessionListPayload,
+ GetSessionListResponse as ProtobufGetSessionListResponse, GetTabInfoPayload,
+ GetTabInfoResponse as ProtobufGetTabInfoResponse, GoToTabWithIdPayload,
GroupAndUngroupPanesPayload, HideFloatingPanesPayload as ProtobufHideFloatingPanesPayload,
HideFloatingPanesResponse as ProtobufHideFloatingPanesResponse, HidePaneWithIdPayload,
HighlightAndUnhighlightPanesPayload, HighlightLayer as ProtobufHighlightLayer,
@@ -108,9 +114,10 @@ pub use super::generated_api::api::{
SaveLayoutPayload, SaveLayoutResponse as ProtobufSaveLayoutResponse, SaveSessionPayload,
SaveSessionResponse as ProtobufSaveSessionResponse, ScrollDownInPaneIdPayload,
ScrollToBottomInPaneIdPayload, ScrollToTopInPaneIdPayload, ScrollUpInPaneIdPayload,
- SetFloatingPanePinnedPayload, SetPaneBorderlessPayload, SetPaneColorPayload,
- SetPaneRegexHighlightsPayload, SetSelfMouseSelectionSupportPayload, SetTimeoutPayload,
- ShowCursorPayload, ShowFloatingPanesPayload as ProtobufShowFloatingPanesPayload,
+ SessionListSnapshot as ProtobufSessionListSnapshot, SetFloatingPanePinnedPayload,
+ SetPaneBorderlessPayload, SetPaneColorPayload, SetPaneRegexHighlightsPayload,
+ SetSelfMouseSelectionSupportPayload, SetTimeoutPayload, ShowCursorPayload,
+ ShowFloatingPanesPayload as ProtobufShowFloatingPanesPayload,
ShowFloatingPanesResponse as ProtobufShowFloatingPanesResponse, ShowPaneWithIdPayload,
StackPanesPayload, SubscribePayload, SwitchSessionPayload, SwitchTabToIdPayload,
SwitchTabToPayload, TogglePaneBorderlessPayload, TogglePaneEmbedOrEjectForPaneIdPayload,
@@ -124,9 +131,10 @@ pub use super::generated_api::api::{
use crate::data::{
ConnectToSession, DeleteLayoutResponse, EditLayoutResponse, FloatingPaneCoordinates,
GetFocusedPaneInfoResponse, GetPaneCwdResponse, GetPanePidResponse,
- GetPaneRunningCommandResponse, HighlightLayer, HighlightStyle, HttpVerb, InputMode,
- KeyWithModifier, MessageToPlugin, NewPluginArgs, PaneId, PermissionType, PluginCommand,
- RegexHighlight, RenameLayoutResponse, SaveLayoutResponse,
+ GetPaneRunningCommandResponse, GetSessionListResponse, HighlightLayer, HighlightStyle,
+ HttpVerb, InputMode, KeyWithModifier, MessageToPlugin, NewPluginArgs, PaneId, PermissionType,
+ PluginCommand, RegexHighlight, RenameLayoutResponse, SaveLayoutResponse, SessionInfo,
+ SessionListSnapshot,
};
use crate::input::actions::Action;
use crate::input::layout::PercentOrFixed;
@@ -329,6 +337,63 @@ impl From<GetPaneRunningCommandResponse> for ProtobufGetPaneRunningCommandRespon
}
}
+impl From<GetSessionListResponse> for ProtobufGetSessionListResponse {
+ fn from(response: GetSessionListResponse) -> Self {
+ match response {
+ GetSessionListResponse::Ok(snapshot) => {
+ let live_sessions = snapshot
+ .live_sessions
+ .into_iter()
+ .filter_map(|si| ProtobufSessionManifest::try_from(si).ok())
+ .collect();
+ let resurrectable_sessions = snapshot
+ .resurrectable_sessions
+ .into_iter()
+ .map(|entry| ProtobufResurrectableSession::from(entry))
+ .collect();
+ ProtobufGetSessionListResponse {
+ result: Some(get_session_list_response::Result::Snapshot(
+ ProtobufSessionListSnapshot {
+ live_sessions,
+ resurrectable_sessions,
+ },
+ )),
+ }
+ },
+ GetSessionListResponse::Err(err) => ProtobufGetSessionListResponse {
+ result: Some(get_session_list_response::Result::Error(err)),
+ },
+ }
+ }
+}
+
+impl TryFrom<ProtobufGetSessionListResponse> for GetSessionListResponse {
+ type Error = &'static str;
+ fn try_from(protobuf_response: ProtobufGetSessionListResponse) -> Result<Self, &'static str> {
+ match protobuf_response.result {
+ Some(get_session_list_response::Result::Snapshot(snapshot)) => {
+ let mut live_sessions: Vec<SessionInfo> = Vec::new();
+ for manifest in snapshot.live_sessions {
+ live_sessions.push(SessionInfo::try_from(manifest)?);
+ }
+ let resurrectable_sessions = snapshot
+ .resurrectable_sessions
+ .into_iter()
+ .map(<(String, std::time::Duration)>::from)
+ .collect();
+ Ok(GetSessionListResponse::Ok(SessionListSnapshot {
+ live_sessions,
+ resurrectable_sessions,
+ }))
+ },
+ Some(get_session_list_response::Result::Error(err)) => {
+ Ok(GetSessionListResponse::Err(err))
+ },
+ None => Err("Empty GetSessionListResponse"),
+ }
+ }
+}
+
impl From<GetPaneCwdResponse> for ProtobufGetPaneCwdResponse {
fn from(response: GetPaneCwdResponse) -> Self {
match response {
@@ -1300,6 +1365,11 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
Some(_) => Err("ListWindowsVolumes should have no payload"),
None => Ok(PluginCommand::ListWindowsVolumes),
},
+ Some(CommandName::GetSessionList) => match protobuf_plugin_command.payload {
+ Some(Payload::GetSessionListPayload(_)) => Ok(PluginCommand::GetSessionList),
+ None => Ok(PluginCommand::GetSessionList),
+ _ => Err("Mismatched payload for GetSessionList"),
+ },
Some(CommandName::DumpSessionLayout) => match protobuf_plugin_command.payload {
Some(Payload::DumpSessionLayoutPayload(payload)) => {
Ok(PluginCommand::DumpSessionLayout {
@@ -3145,6 +3215,12 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::ListWindowsVolumes as i32,
payload: None,
}),
+ PluginCommand::GetSessionList => Ok(ProtobufPluginCommand {
+ name: CommandName::GetSessionList as i32,
+ payload: Some(Payload::GetSessionListPayload(
+ ProtobufGetSessionListPayload {},
+ )),
+ }),
PluginCommand::DumpSessionLayout { tab_index } => Ok(ProtobufPluginCommand {
name: CommandName::DumpSessionLayout as i32,
payload: tab_index.map(|idx| {