diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-06-29 18:10:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-29 18:10:59 +0200 |
| commit | 245f5141c9bb7eb91f003efac4defc94470243fd (patch) | |
| tree | 52ae6d003366f97e41c8a1450602aef63c8fdca2 /zellij-utils/src/plugin_api | |
| parent | feat: reload config on theme change (#5135) (diff) | |
| download | sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.tar.gz sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.tar.xz sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.zip | |
Title frames (#5318)
* initial implementation
* improve single line title design
* hint text plugin infra
* add proto regen task
* display alt text in status bar
* don't display text with full frames
* style alt hover text
* fix + style control own pane hover
* make multiplayer indications responsive
* update snapshots
* plugin api
* single pane as tab
* better scroll styling
* fix tests
* tab-bar plus hover
* plugin surface tests
* integration tests
* adjust all integration tests
* reduce hover noise
* add pane id to in place
* more integration tests
* style: rustfmt
* update plugin assets
* update assets and snapshots
* add pr
Diffstat (limited to 'zellij-utils/src/plugin_api')
| -rw-r--r-- | zellij-utils/src/plugin_api/action.proto | 7 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/action.rs | 42 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/event.proto | 29 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/event.rs | 176 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/mod.rs | 1 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/pane_frame_style.proto | 9 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/pane_frame_style.rs | 49 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/plugin_command.proto | 14 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/plugin_command.rs | 110 |
9 files changed, 428 insertions, 9 deletions
diff --git a/zellij-utils/src/plugin_api/action.proto b/zellij-utils/src/plugin_api/action.proto index 68c859b8..f9370961 100644 --- a/zellij-utils/src/plugin_api/action.proto +++ b/zellij-utils/src/plugin_api/action.proto @@ -2,6 +2,7 @@ syntax = "proto3"; import "input_mode.proto"; import "resize.proto"; +import "pane_frame_style.proto"; package api.action; @@ -245,9 +246,14 @@ message Action { ShowFloatingPanesPayload show_floating_panes_payload = 58; HideFloatingPanesPayload hide_floating_panes_payload = 59; AreFloatingPanesVisiblePayload are_floating_panes_visible_payload = 60; + SetPaneFrameStylePayload set_pane_frame_style_payload = 61; } } +message SetPaneFrameStylePayload { + pane_frame_style.PaneFrameStyle pane_frame_style = 1; +} + message CliPipePayload { optional string name = 1; string payload = 2; @@ -494,6 +500,7 @@ enum ActionName { SetLightTheme = 102; ToggleTheme = 103; FocusLastPane = 104; + SetPaneFrameStyle = 105; } message Position { diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs index f4e35d84..209bff3f 100644 --- a/zellij-utils/src/plugin_api/action.rs +++ b/zellij-utils/src/plugin_api/action.rs @@ -58,6 +58,7 @@ pub use super::generated_api::api::{ ScrollAtPayload, SearchDirection as ProtobufSearchDirection, SearchOption as ProtobufSearchOption, + SetPaneFrameStylePayload, ShowFloatingPanesPayload, SplitDirection as ProtobufSplitDirection, SplitSize as ProtobufSplitSize, @@ -74,6 +75,7 @@ pub use super::generated_api::api::{ WritePayload, }, input_mode::InputMode as ProtobufInputMode, + pane_frame_style::PaneFrameStyle as ProtobufPaneFrameStyle, resize::{Resize as ProtobufResize, ResizeDirection as ProtobufResizeDirection}, }; use crate::data::{ @@ -300,6 +302,17 @@ impl TryFrom<ProtobufAction> for Action { Some(_) => Err("TogglePaneFrames should not have a payload"), None => Ok(Action::TogglePaneFrames), }, + Some(ProtobufActionName::SetPaneFrameStyle) => match protobuf_action.optional_payload { + Some(OptionalPayload::SetPaneFrameStylePayload(payload)) => { + match ProtobufPaneFrameStyle::from_i32(payload.pane_frame_style) { + Some(protobuf_pane_frame_style) => Ok(Action::SetPaneFrameStyle( + protobuf_pane_frame_style.try_into()?, + )), + None => Err("Malformed payload for Action::SetPaneFrameStyle"), + } + }, + _ => Err("Wrong payload for Action::SetPaneFrameStyle"), + }, Some(ProtobufActionName::ToggleActiveSyncTab) => { match protobuf_action.optional_payload { Some(_) => Err("ToggleActiveSyncTab should not have a payload"), @@ -1301,6 +1314,15 @@ impl TryFrom<Action> for ProtobufAction { name: ProtobufActionName::TogglePaneFrames as i32, optional_payload: None, }), + Action::SetPaneFrameStyle(pane_frame_style) => Ok(ProtobufAction { + name: ProtobufActionName::SetPaneFrameStyle as i32, + optional_payload: Some(OptionalPayload::SetPaneFrameStylePayload( + SetPaneFrameStylePayload { + pane_frame_style: ProtobufPaneFrameStyle::try_from(pane_frame_style)? + as i32, + }, + )), + }), Action::ToggleActiveSyncTab => Ok(ProtobufAction { name: ProtobufActionName::ToggleActiveSyncTab as i32, optional_payload: None, @@ -3235,3 +3257,23 @@ impl TryFrom<SwapFloatingLayout> for ProtobufSwapFloatingLayout { }) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::input::options::PaneFrameStyle; + + #[test] + fn set_pane_frame_style_action_protobuf_round_trip() { + for style in [ + PaneFrameStyle::Full, + PaneFrameStyle::Titles, + PaneFrameStyle::None, + ] { + let original = Action::SetPaneFrameStyle(style); + let protobuf: ProtobufAction = original.clone().try_into().expect("encode"); + let decoded: Action = protobuf.try_into().expect("decode"); + assert_eq!(original, decoded); + } + } +} diff --git a/zellij-utils/src/plugin_api/event.proto b/zellij-utils/src/plugin_api/event.proto index 2567c657..d3148edf 100644 --- a/zellij-utils/src/plugin_api/event.proto +++ b/zellij-utils/src/plugin_api/event.proto @@ -70,6 +70,8 @@ enum EventType { CommandChanged = 45; HostTerminalThemeChanged = 46; SoftKeyboardVisibilityChanged = 47; + HintText = 48; + ActivePaneScroll = 49; } message EventNameList { @@ -119,9 +121,29 @@ message Event { CommandChangedPayload command_changed_payload = 39; HostTerminalThemeChangedPayload host_terminal_theme_changed_payload = 40; SoftKeyboardVisibilityChangedPayload soft_keyboard_visibility_changed_payload = 41; + HintTextPayload hint_text_payload = 42; + ActivePaneScrollPayload active_pane_scroll_payload = 43; } } +message HintTextPayload { + map<uint32, StyledText> hint_text = 1; +} + +message ActivePaneScrollPayload { + optional uint32 position = 1; + optional uint32 length = 2; +} + +message StyledText { + string text = 1; + repeated StyledTextIndices indices = 2; +} + +message StyledTextIndices { + repeated uint32 indices = 1; +} + message HostTerminalThemeChangedPayload { HostTerminalThemeIndication mode = 1; } @@ -488,6 +510,7 @@ message ModeUpdatePayload { optional string web_server_ip = 13; optional uint32 web_server_port = 14; optional bool web_server_capability = 15; + optional PaneFrameStyle pane_frame_style = 16; } enum WebSharing { @@ -496,6 +519,12 @@ enum WebSharing { Disabled = 2; } +enum PaneFrameStyle { + Full = 0; + Titles = 1; + None = 2; +} + message InputModeKeybinds { input_mode.InputMode mode = 1; repeated KeyBind key_bind = 2; diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index 5ba106d0..190552d4 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -4,6 +4,7 @@ pub use super::generated_api::api::{ event::Payload as ProtobufEventPayload, layout_parsing_error::ErrorType as ProtobufLayoutParsingErrorType, pane_scrollback_response, ActionCompletePayload as ProtobufActionCompletePayload, + ActivePaneScrollPayload as ProtobufActivePaneScrollPayload, AvailableLayoutInfoPayload as ProtobufAvailableLayoutInfoPayload, ClientInfo as ProtobufClientInfo, ClientPaneHistory as ProtobufClientPaneHistory, ClientTabHistory as ProtobufClientTabHistory, @@ -11,6 +12,7 @@ pub use super::generated_api::api::{ CopyDestination as ProtobufCopyDestination, CwdChangedPayload as ProtobufCwdChangedPayload, Event as ProtobufEvent, EventNameList as ProtobufEventNameList, EventType as ProtobufEventType, FileMetadata as ProtobufFileMetadata, + HintTextPayload as ProtobufHintTextPayload, HostTerminalThemeChangedPayload as ProtobufHostTerminalThemeChangedPayload, HostTerminalThemeIndication as ProtobufHostTerminalThemeIndication, InputModeKeybinds as ProtobufInputModeKeybinds, KdlError as ProtobufKdlError, @@ -19,14 +21,16 @@ pub use super::generated_api::api::{ LayoutParsingError as ProtobufLayoutParsingError, LayoutWithError as ProtobufLayoutWithError, ModeUpdatePayload as ProtobufModeUpdatePayload, PaneContents as ProtobufPaneContents, PaneContentsEntry as ProtobufPaneContentsEntry, - PaneId as ProtobufPaneId, PaneInfo as ProtobufPaneInfo, - PaneManifest as ProtobufPaneManifest, PaneMetadata as ProtobufPaneMetadata, + PaneFrameStyle as ProtobufPaneFrameStyle, PaneId as ProtobufPaneId, + PaneInfo as ProtobufPaneInfo, PaneManifest as ProtobufPaneManifest, + PaneMetadata as ProtobufPaneMetadata, PaneRenderReportPayload as ProtobufPaneRenderReportPayload, PaneScrollbackResponse as ProtobufPaneScrollbackResponse, PaneType as ProtobufPaneType, PluginConfigurationChangedPayload as ProtobufPluginConfigurationChangedPayload, PluginInfo as ProtobufPluginInfo, ResurrectableSession as ProtobufResurrectableSession, SelectedText as ProtobufSelectedText, SessionManifest as ProtobufSessionManifest, SoftKeyboardVisibilityChangedPayload as ProtobufSoftKeyboardVisibilityChangedPayload, + StyledText as ProtobufStyledText, StyledTextIndices as ProtobufStyledTextIndices, SyntaxError as ProtobufSyntaxError, TabInfo as ProtobufTabInfo, TabMetadata as ProtobufTabMetadata, UserActionPayload as ProtobufUserActionPayload, WebServerStatusPayload as ProtobufWebServerStatusPayload, WebSharing as ProtobufWebSharing, @@ -41,8 +45,8 @@ use crate::data::{ ClientId, ClientInfo, CopyDestination, Event, EventType, FileMetadata, HostTerminalThemeMode, InputMode, KeyWithModifier, LayoutInfo, LayoutMetadata, ModeInfo, Mouse, PaneContents, PaneId, PaneInfo, PaneManifest, PaneMetadata, PaneScrollbackResponse, PermissionStatus, - PluginCapabilities, PluginInfo, SelectedText, SessionInfo, Style, TabInfo, TabMetadata, - WebServerStatus, WebSharing, + PluginCapabilities, PluginInfo, SelectedText, SessionInfo, Style, StyledText, TabInfo, + TabMetadata, WebServerStatus, WebSharing, }; use crate::errors::prelude::*; @@ -597,6 +601,28 @@ impl TryFrom<ProtobufEvent> for Event { _ => Err("Malformed payload for SoftKeyboardVisibilityChanged Event"), } }, + Some(ProtobufEventType::HintText) => match protobuf_event.payload { + Some(ProtobufEventPayload::HintTextPayload(p)) => { + let mut hint_text = BTreeMap::new(); + for (width, styled_text) in p.hint_text { + hint_text.insert(width as usize, StyledText::from(styled_text)); + } + Ok(Event::HintText(hint_text)) + }, + _ => Err("Malformed payload for HintText Event"), + }, + Some(ProtobufEventType::ActivePaneScroll) => match protobuf_event.payload { + Some(ProtobufEventPayload::ActivePaneScrollPayload(p)) => { + let scroll = match (p.position, p.length) { + (Some(position), Some(length)) => { + Some((position as usize, length as usize)) + }, + _ => None, + }; + Ok(Event::ActivePaneScroll(scroll)) + }, + _ => Err("Malformed payload for ActivePaneScroll Event"), + }, None => Err("Unknown Protobuf Event"), } } @@ -1147,6 +1173,35 @@ impl TryFrom<Event> for ProtobufEvent { )), }) }, + Event::HintText(hint_text) => { + let mut proto_hint_text = HashMap::new(); + for (width, styled_text) in hint_text { + proto_hint_text.insert(width as u32, ProtobufStyledText::from(styled_text)); + } + let payload = ProtobufHintTextPayload { + hint_text: proto_hint_text, + }; + Ok(ProtobufEvent { + name: ProtobufEventType::HintText as i32, + payload: Some(event::Payload::HintTextPayload(payload)), + }) + }, + Event::ActivePaneScroll(scroll) => { + let payload = match scroll { + Some((position, length)) => ProtobufActivePaneScrollPayload { + position: Some(position as u32), + length: Some(length as u32), + }, + None => ProtobufActivePaneScrollPayload { + position: None, + length: None, + }, + }; + Ok(ProtobufEvent { + name: ProtobufEventType::ActivePaneScroll as i32, + payload: Some(event::Payload::ActivePaneScrollPayload(payload)), + }) + }, Event::InitialKeybinds(keybinds) => { let mut protobuf_keybinds: Vec<ProtobufInputModeKeybinds> = vec![]; for (input_mode, input_mode_keybinds) in keybinds { @@ -1960,6 +2015,11 @@ impl TryFrom<ProtobufModeUpdatePayload> for ModeInfo { let web_server_capability = protobuf_mode_update_payload.web_server_capability; + let pane_frame_style = protobuf_mode_update_payload + .pane_frame_style + .and_then(|p| ProtobufPaneFrameStyle::from_i32(p)) + .map(|p| p.into()); + let mode_info = ModeInfo { mode: current_mode, keybinds, @@ -1976,6 +2036,7 @@ impl TryFrom<ProtobufModeUpdatePayload> for ModeInfo { web_server_ip, web_server_port, web_server_capability, + pane_frame_style, }; Ok(mode_info) } @@ -2000,6 +2061,10 @@ impl TryFrom<ModeInfo> for ProtobufModeUpdatePayload { let web_server_ip = mode_info.web_server_ip.map(|i| format!("{}", i)); let web_server_port = mode_info.web_server_port.map(|p| p as u32); let web_server_capability = mode_info.web_server_capability; + let pane_frame_style = mode_info.pane_frame_style.map(|p| { + let protobuf_pane_frame_style: ProtobufPaneFrameStyle = p.into(); + protobuf_pane_frame_style as i32 + }); let mut protobuf_input_mode_keybinds: Vec<ProtobufInputModeKeybinds> = vec![]; for (input_mode, input_mode_keybinds) in mode_info.keybinds { let mode: ProtobufInputMode = input_mode.try_into()?; @@ -2040,6 +2105,7 @@ impl TryFrom<ModeInfo> for ProtobufModeUpdatePayload { web_server_ip, web_server_port, web_server_capability, + pane_frame_style, }) } } @@ -2127,6 +2193,8 @@ impl TryFrom<ProtobufEventType> for EventType { ProtobufEventType::SoftKeyboardVisibilityChanged => { EventType::SoftKeyboardVisibilityChanged }, + ProtobufEventType::HintText => EventType::HintText, + ProtobufEventType::ActivePaneScroll => EventType::ActivePaneScroll, }) } } @@ -2184,10 +2252,40 @@ impl TryFrom<EventType> for ProtobufEventType { EventType::SoftKeyboardVisibilityChanged => { ProtobufEventType::SoftKeyboardVisibilityChanged }, + EventType::HintText => ProtobufEventType::HintText, + EventType::ActivePaneScroll => ProtobufEventType::ActivePaneScroll, }) } } +impl From<StyledText> for ProtobufStyledText { + fn from(styled_text: StyledText) -> Self { + ProtobufStyledText { + text: styled_text.text, + indices: styled_text + .indices + .into_iter() + .map(|inner| ProtobufStyledTextIndices { + indices: inner.into_iter().map(|i| i as u32).collect(), + }) + .collect(), + } + } +} + +impl From<ProtobufStyledText> for StyledText { + fn from(styled_text: ProtobufStyledText) -> Self { + StyledText { + text: styled_text.text, + indices: styled_text + .indices + .into_iter() + .map(|inner| inner.indices.into_iter().map(|i| i as usize).collect()) + .collect(), + } + } +} + impl From<HostTerminalThemeMode> for ProtobufHostTerminalThemeIndication { fn from(mode: HostTerminalThemeMode) -> Self { match mode { @@ -2361,6 +2459,7 @@ fn serialize_mode_update_event_with_non_default_values() { web_server_ip: IpAddr::from_str("127.0.0.1").ok(), web_server_port: Some(8082), web_server_capability: Some(true), + pane_frame_style: Some(crate::input::options::PaneFrameStyle::Titles), }); let protobuf_event: ProtobufEvent = mode_update_event.clone().try_into().unwrap(); let serialized_protobuf_event = protobuf_event.encode_to_vec(); @@ -2463,6 +2562,55 @@ fn serialize_pane_update_event() { } #[test] +fn serialize_hint_text_event() { + use prost::Message; + let hint_text_event = Event::HintText(BTreeMap::from([ + ( + 10, + StyledText { + text: "group".to_owned(), + indices: vec![vec![0]], + }, + ), + ( + 42, + StyledText { + text: "resize".to_owned(), + indices: vec![vec![0, 1], vec![3]], + }, + ), + ])); + let protobuf_event: ProtobufEvent = hint_text_event.clone().try_into().unwrap(); + let serialized_protobuf_event = protobuf_event.encode_to_vec(); + let deserialized_protobuf_event: ProtobufEvent = + Message::decode(serialized_protobuf_event.as_slice()).unwrap(); + let deserialized_event: Event = deserialized_protobuf_event.try_into().unwrap(); + assert_eq!( + hint_text_event, deserialized_event, + "Event properly serialized/deserialized without change" + ); +} + +#[test] +fn serialize_active_pane_scroll_event() { + use prost::Message; + for active_pane_scroll_event in [ + Event::ActivePaneScroll(Some((3, 12))), + Event::ActivePaneScroll(None), + ] { + let protobuf_event: ProtobufEvent = active_pane_scroll_event.clone().try_into().unwrap(); + let serialized_protobuf_event = protobuf_event.encode_to_vec(); + let deserialized_protobuf_event: ProtobufEvent = + Message::decode(serialized_protobuf_event.as_slice()).unwrap(); + let deserialized_event: Event = deserialized_protobuf_event.try_into().unwrap(); + assert_eq!( + active_pane_scroll_event, deserialized_event, + "Event properly serialized/deserialized without change" + ); + } +} + +#[test] fn serialize_key_event() { use crate::data::BareKey; use prost::Message; @@ -2946,6 +3094,26 @@ impl Into<WebSharing> for ProtobufWebSharing { } } +impl Into<ProtobufPaneFrameStyle> for crate::input::options::PaneFrameStyle { + fn into(self) -> ProtobufPaneFrameStyle { + match self { + crate::input::options::PaneFrameStyle::Full => ProtobufPaneFrameStyle::Full, + crate::input::options::PaneFrameStyle::Titles => ProtobufPaneFrameStyle::Titles, + crate::input::options::PaneFrameStyle::None => ProtobufPaneFrameStyle::None, + } + } +} + +impl Into<crate::input::options::PaneFrameStyle> for ProtobufPaneFrameStyle { + fn into(self) -> crate::input::options::PaneFrameStyle { + match self { + ProtobufPaneFrameStyle::Full => crate::input::options::PaneFrameStyle::Full, + ProtobufPaneFrameStyle::Titles => crate::input::options::PaneFrameStyle::Titles, + ProtobufPaneFrameStyle::None => crate::input::options::PaneFrameStyle::None, + } + } +} + impl TryFrom<WebServerStatus> for ProtobufWebServerStatusPayload { type Error = &'static str; fn try_from(web_server_status: WebServerStatus) -> Result<Self, &'static str> { diff --git a/zellij-utils/src/plugin_api/mod.rs b/zellij-utils/src/plugin_api/mod.rs index 0e26485e..918ad4ae 100644 --- a/zellij-utils/src/plugin_api/mod.rs +++ b/zellij-utils/src/plugin_api/mod.rs @@ -5,6 +5,7 @@ pub mod file; pub mod input_mode; pub mod key; pub mod message; +pub mod pane_frame_style; pub mod pipe_message; pub mod plugin_command; pub mod plugin_ids; diff --git a/zellij-utils/src/plugin_api/pane_frame_style.proto b/zellij-utils/src/plugin_api/pane_frame_style.proto new file mode 100644 index 00000000..0acd8bee --- /dev/null +++ b/zellij-utils/src/plugin_api/pane_frame_style.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package api.pane_frame_style; + +enum PaneFrameStyle { + Full = 0; + Titles = 1; + None = 2; +} diff --git a/zellij-utils/src/plugin_api/pane_frame_style.rs b/zellij-utils/src/plugin_api/pane_frame_style.rs new file mode 100644 index 00000000..392f2e89 --- /dev/null +++ b/zellij-utils/src/plugin_api/pane_frame_style.rs @@ -0,0 +1,49 @@ +pub use super::generated_api::api::pane_frame_style::PaneFrameStyle as ProtobufPaneFrameStyle; +use crate::input::options::PaneFrameStyle; + +use std::convert::TryFrom; + +impl TryFrom<ProtobufPaneFrameStyle> for PaneFrameStyle { + type Error = &'static str; + fn try_from(protobuf_pane_frame_style: ProtobufPaneFrameStyle) -> Result<Self, &'static str> { + match protobuf_pane_frame_style { + ProtobufPaneFrameStyle::Full => Ok(PaneFrameStyle::Full), + ProtobufPaneFrameStyle::Titles => Ok(PaneFrameStyle::Titles), + ProtobufPaneFrameStyle::None => Ok(PaneFrameStyle::None), + } + } +} + +impl TryFrom<PaneFrameStyle> for ProtobufPaneFrameStyle { + type Error = &'static str; + fn try_from(pane_frame_style: PaneFrameStyle) -> Result<Self, &'static str> { + Ok(match pane_frame_style { + PaneFrameStyle::Full => ProtobufPaneFrameStyle::Full, + PaneFrameStyle::Titles => ProtobufPaneFrameStyle::Titles, + PaneFrameStyle::None => ProtobufPaneFrameStyle::None, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn pane_frame_style_roundtrips_through_protobuf() { + for style in [ + PaneFrameStyle::Full, + PaneFrameStyle::Titles, + PaneFrameStyle::None, + ] { + let protobuf: ProtobufPaneFrameStyle = style.try_into().unwrap(); + let roundtripped: PaneFrameStyle = protobuf.try_into().unwrap(); + assert_eq!(style, roundtripped); + } + } + + #[test] + fn unknown_pane_frame_style_value_is_rejected() { + assert!(ProtobufPaneFrameStyle::from_i32(99).is_none()); + } +} diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto index 82f4d835..8d31727d 100644 --- a/zellij-utils/src/plugin_api/plugin_command.proto +++ b/zellij-utils/src/plugin_api/plugin_command.proto @@ -9,6 +9,7 @@ import "resize.proto"; import "plugin_permission.proto"; import "input_mode.proto"; import "key.proto"; +import "pane_frame_style.proto"; package api.plugin_command; @@ -214,6 +215,9 @@ enum CommandName { NewTiledPaneInTab = 221; ExitMobileMode = 222; FocusLastPane = 223; + SetPaneFrameStyle = 224; + ToggleFloatingPanes = 225; + NewPane = 226; } message PluginCommand { @@ -373,9 +377,19 @@ message PluginCommand { PaneId set_shadow_focus_payload = 167; NewTabUnfocusedPayload new_tab_unfocused_payload = 168; NewTiledPaneInTabPayload new_tiled_pane_in_tab_payload = 169; + SetPaneFrameStylePayload set_pane_frame_style_payload = 170; + ToggleFloatingPanesPayload toggle_floating_panes_payload = 171; } } +message SetPaneFrameStylePayload { + pane_frame_style.PaneFrameStyle pane_frame_style = 1; +} + +message ToggleFloatingPanesPayload { + optional uint64 tab_id = 1; +} + message NewTabPayload { optional string name = 1; optional string cwd = 2; diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs index 546c3586..38c42565 100644 --- a/zellij-utils/src/plugin_api/plugin_command.rs +++ b/zellij-utils/src/plugin_api/plugin_command.rs @@ -6,6 +6,7 @@ pub use super::generated_api::api::{ SessionManifest as ProtobufSessionManifest, }, input_mode::InputMode as ProtobufInputMode, + pane_frame_style::PaneFrameStyle as ProtobufPaneFrameStyle, 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, @@ -120,16 +121,18 @@ pub use super::generated_api::api::{ SaveSessionResponse as ProtobufSaveSessionResponse, ScrollDownInPaneIdPayload, ScrollToBottomInPaneIdPayload, ScrollToTopInPaneIdPayload, ScrollUpInPaneIdPayload, SessionListSnapshot as ProtobufSessionListSnapshot, SetFloatingPanePinnedPayload, - SetPaneBorderlessPayload, SetPaneColorPayload, SetPaneRegexHighlightsPayload, - SetSelfMouseSelectionSupportPayload, + SetPaneBorderlessPayload, SetPaneColorPayload, + SetPaneFrameStylePayload as ProtobufSetPaneFrameStylePayload, + SetPaneRegexHighlightsPayload, SetSelfMouseSelectionSupportPayload, SetSoftKeyboardPayload as ProtobufSetSoftKeyboardPayload, SetTabFitPayload as ProtobufSetTabFitPayload, SetTimeoutPayload, ShowCursorPayload, ShowFloatingPanesPayload as ProtobufShowFloatingPanesPayload, ShowFloatingPanesResponse as ProtobufShowFloatingPanesResponse, ShowPaneWithIdPayload, Size as ProtobufSize, StackPanesPayload, SubscribePayload, SwitchSessionPayload, - SwitchTabToIdPayload, SwitchTabToPayload, TogglePaneBorderlessPayload, - TogglePaneEmbedOrEjectForPaneIdPayload, TogglePaneIdFullscreenPayload, UnsubscribePayload, - WebRequestPayload, WriteCharsToPaneIdPayload, WriteToPaneIdPayload, + SwitchTabToIdPayload, SwitchTabToPayload, ToggleFloatingPanesPayload, + TogglePaneBorderlessPayload, TogglePaneEmbedOrEjectForPaneIdPayload, + TogglePaneIdFullscreenPayload, UnsubscribePayload, WebRequestPayload, + WriteCharsToPaneIdPayload, WriteToPaneIdPayload, }, plugin_permission::PermissionType as ProtobufPermissionType, resize::ResizeAction as ProtobufResizeAction, @@ -940,6 +943,20 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand { }, _ => Err("Mismatched payload for NewTiledPaneInTab"), }, + Some(CommandName::ToggleFloatingPanes) => match protobuf_plugin_command.payload { + Some(Payload::ToggleFloatingPanesPayload(payload)) => { + Ok(PluginCommand::ToggleFloatingPanes { + tab_id: payload.tab_id, + }) + }, + _ => Ok(PluginCommand::ToggleFloatingPanes { tab_id: None }), + }, + Some(CommandName::NewPane) => { + if protobuf_plugin_command.payload.is_some() { + return Err("NewPane should not have a payload"); + } + Ok(PluginCommand::NewPane) + }, Some(CommandName::GoToNextTab) => { if protobuf_plugin_command.payload.is_some() { return Err("GoToNextTab should not have a payload"); @@ -1099,6 +1116,17 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand { } Ok(PluginCommand::TogglePaneFrames) }, + Some(CommandName::SetPaneFrameStyle) => match protobuf_plugin_command.payload { + Some(Payload::SetPaneFrameStylePayload(payload)) => { + match ProtobufPaneFrameStyle::from_i32(payload.pane_frame_style) { + Some(protobuf_pane_frame_style) => Ok(PluginCommand::SetPaneFrameStyle( + protobuf_pane_frame_style.try_into()?, + )), + None => Err("Malformed SetPaneFrameStyle payload"), + } + }, + _ => Err("Mismatched payload for SetPaneFrameStyle"), + }, Some(CommandName::TogglePaneEmbedOrEject) => { if protobuf_plugin_command.payload.is_some() { return Err("TogglePaneEmbedOrEject should not have a payload"); @@ -2983,6 +3011,16 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand { }, )), }), + PluginCommand::ToggleFloatingPanes { tab_id } => Ok(ProtobufPluginCommand { + name: CommandName::ToggleFloatingPanes as i32, + payload: Some(Payload::ToggleFloatingPanesPayload( + ToggleFloatingPanesPayload { tab_id }, + )), + }), + PluginCommand::NewPane => Ok(ProtobufPluginCommand { + name: CommandName::NewPane as i32, + payload: None, + }), PluginCommand::GoToNextTab => Ok(ProtobufPluginCommand { name: CommandName::GoToNextTab as i32, payload: None, @@ -3093,6 +3131,15 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand { name: CommandName::TogglePaneFrames as i32, payload: None, }), + PluginCommand::SetPaneFrameStyle(pane_frame_style) => Ok(ProtobufPluginCommand { + name: CommandName::SetPaneFrameStyle as i32, + payload: Some(Payload::SetPaneFrameStylePayload( + ProtobufSetPaneFrameStylePayload { + pane_frame_style: ProtobufPaneFrameStyle::try_from(pane_frame_style)? + as i32, + }, + )), + }), PluginCommand::TogglePaneEmbedOrEject => Ok(ProtobufPluginCommand { name: CommandName::TogglePaneEmbedOrEject as i32, payload: None, @@ -5265,4 +5312,57 @@ mod tests { other => panic!("expected SetTabFit, got {:?}", other), } } + + #[test] + fn set_pane_frame_style_protobuf_round_trip() { + use crate::input::options::PaneFrameStyle; + for style in [ + PaneFrameStyle::Full, + PaneFrameStyle::Titles, + PaneFrameStyle::None, + ] { + let original = PluginCommand::SetPaneFrameStyle(style); + let protobuf: ProtobufPluginCommand = original.try_into().expect("encode"); + let decoded: PluginCommand = protobuf.try_into().expect("decode"); + match decoded { + PluginCommand::SetPaneFrameStyle(decoded_style) => { + assert_eq!(decoded_style, style) + }, + other => panic!("expected SetPaneFrameStyle, got {:?}", other), + } + } + } + + #[test] + fn new_pane_protobuf_round_trip() { + let original = PluginCommand::NewPane; + let protobuf: ProtobufPluginCommand = original.try_into().expect("encode"); + let decoded: PluginCommand = protobuf.try_into().expect("decode"); + match decoded { + PluginCommand::NewPane => {}, + other => panic!("expected NewPane, got {:?}", other), + } + } + + #[test] + fn toggle_floating_panes_focused_tab_protobuf_round_trip() { + let original = PluginCommand::ToggleFloatingPanes { tab_id: None }; + let protobuf: ProtobufPluginCommand = original.try_into().expect("encode"); + let decoded: PluginCommand = protobuf.try_into().expect("decode"); + match decoded { + PluginCommand::ToggleFloatingPanes { tab_id } => assert_eq!(tab_id, None), + other => panic!("expected ToggleFloatingPanes, got {:?}", other), + } + } + + #[test] + fn toggle_floating_panes_with_tab_id_protobuf_round_trip() { + let original = PluginCommand::ToggleFloatingPanes { tab_id: Some(2) }; + let protobuf: ProtobufPluginCommand = original.try_into().expect("encode"); + let decoded: PluginCommand = protobuf.try_into().expect("decode"); + match decoded { + PluginCommand::ToggleFloatingPanes { tab_id } => assert_eq!(tab_id, Some(2)), + other => panic!("expected ToggleFloatingPanes, got {:?}", other), + } + } } |
