diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-06 14:26:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 14:26:14 +0100 |
commit | 6b20a958f4e8db5614fffb27fe5d32f07ddfe855 (patch) | |
tree | c8383fb7941b5e0c23cb348a655f2ea0fafd8668 /zellij-utils/src/plugin_api/event.rs | |
parent | 286f7ccc28e3a091e2d3ef5663ae7878056551e6 (diff) |
feat(sessions): welcome screen (#3112)
* prototype - can send layout name for new session from session-manager
* feat(sessions): ui for selecting layout for new session in the session-manager
* fix: send available layouts to plugins
* make tests compile
* fix tests
* improve ui
* fix: respect built-in layouts
* ui for built-in layouts
* some cleanups
* style(fmt): rustfmt
* welcome screen ui
* fix: make sure layout config is not shared between sessions
* allow disconnecting other users from current session and killing other sessions
* fix: respect default layout
* add welcome screen layout
* tests(plugins): new api methods
* fix(session-manager): do not quit welcome screen on esc and break
* fix(plugins): adjust permissions
* style(fmt): rustfmt
* style(fmt): fix warnings
Diffstat (limited to 'zellij-utils/src/plugin_api/event.rs')
-rw-r--r-- | zellij-utils/src/plugin_api/event.rs | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index d9e5341d6..21ff1eff1 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -4,9 +4,9 @@ pub use super::generated_api::api::{ event::Payload as ProtobufEventPayload, CopyDestination as ProtobufCopyDestination, Event as ProtobufEvent, EventNameList as ProtobufEventNameList, EventType as ProtobufEventType, InputModeKeybinds as ProtobufInputModeKeybinds, - KeyBind as ProtobufKeyBind, ModeUpdatePayload as ProtobufModeUpdatePayload, - PaneInfo as ProtobufPaneInfo, PaneManifest as ProtobufPaneManifest, - ResurrectableSession as ProtobufResurrectableSession, + KeyBind as ProtobufKeyBind, LayoutInfo as ProtobufLayoutInfo, + ModeUpdatePayload as ProtobufModeUpdatePayload, PaneInfo as ProtobufPaneInfo, + PaneManifest as ProtobufPaneManifest, ResurrectableSession as ProtobufResurrectableSession, SessionManifest as ProtobufSessionManifest, TabInfo as ProtobufTabInfo, *, }, input_mode::InputMode as ProtobufInputMode, @@ -14,8 +14,8 @@ pub use super::generated_api::api::{ style::Style as ProtobufStyle, }; use crate::data::{ - CopyDestination, Event, EventType, InputMode, Key, ModeInfo, Mouse, PaneInfo, PaneManifest, - PermissionStatus, PluginCapabilities, SessionInfo, Style, TabInfo, + CopyDestination, Event, EventType, InputMode, Key, LayoutInfo, ModeInfo, Mouse, PaneInfo, + PaneManifest, PermissionStatus, PluginCapabilities, SessionInfo, Style, TabInfo, }; use crate::errors::prelude::*; @@ -453,6 +453,11 @@ impl TryFrom<SessionInfo> for ProtobufSessionManifest { .collect(), connected_clients: session_info.connected_clients as u32, is_current_session: session_info.is_current_session, + available_layouts: session_info + .available_layouts + .into_iter() + .filter_map(|l| ProtobufLayoutInfo::try_from(l).ok()) + .collect(), }) } } @@ -485,10 +490,42 @@ impl TryFrom<ProtobufSessionManifest> for SessionInfo { panes, connected_clients: protobuf_session_manifest.connected_clients as usize, is_current_session: protobuf_session_manifest.is_current_session, + available_layouts: protobuf_session_manifest + .available_layouts + .into_iter() + .filter_map(|l| LayoutInfo::try_from(l).ok()) + .collect(), }) } } +impl TryFrom<LayoutInfo> for ProtobufLayoutInfo { + type Error = &'static str; + fn try_from(layout_info: LayoutInfo) -> Result<Self, &'static str> { + match layout_info { + LayoutInfo::File(name) => Ok(ProtobufLayoutInfo { + source: "file".to_owned(), + name, + }), + LayoutInfo::BuiltIn(name) => Ok(ProtobufLayoutInfo { + source: "built-in".to_owned(), + name, + }), + } + } +} + +impl TryFrom<ProtobufLayoutInfo> for LayoutInfo { + type Error = &'static str; + fn try_from(protobuf_layout_info: ProtobufLayoutInfo) -> Result<Self, &'static str> { + match protobuf_layout_info.source.as_str() { + "file" => Ok(LayoutInfo::File(protobuf_layout_info.name)), + "built-in" => Ok(LayoutInfo::BuiltIn(protobuf_layout_info.name)), + _ => Err("Unknown source for layout"), + } + } +} + impl TryFrom<CopyDestination> for ProtobufCopyDestination { type Error = &'static str; fn try_from(copy_destination: CopyDestination) -> Result<Self, &'static str> { @@ -1383,6 +1420,11 @@ fn serialize_session_update_event_with_non_default_values() { panes: PaneManifest { panes }, connected_clients: 2, is_current_session: true, + available_layouts: vec![ + LayoutInfo::File("layout 1".to_owned()), + LayoutInfo::BuiltIn("layout2".to_owned()), + LayoutInfo::File("layout3".to_owned()), + ], }; let session_info_2 = SessionInfo { name: "session 2".to_owned(), @@ -1392,6 +1434,11 @@ fn serialize_session_update_event_with_non_default_values() { }, connected_clients: 0, is_current_session: false, + available_layouts: vec![ + LayoutInfo::File("layout 1".to_owned()), + LayoutInfo::BuiltIn("layout2".to_owned()), + LayoutInfo::File("layout3".to_owned()), + ], }; let session_infos = vec![session_info_1, session_info_2]; let resurrectable_sessions = vec![]; |