diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-11-16 11:47:00 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2024-11-16 11:47:00 +0100 |
| commit | 896c534faebc60b83fe7ea693e8b2014faf8876b (patch) | |
| tree | 646e0c04b2f60ea82d106ba8794f2cd8a1972eb3 | |
| parent | feat: add hide_frame_except_for_fullscreen (diff) | |
| download | sl0pstatus-896c534faebc60b83fe7ea693e8b2014faf8876b.tar.gz sl0pstatus-896c534faebc60b83fe7ea693e8b2014faf8876b.tar.xz sl0pstatus-896c534faebc60b83fe7ea693e8b2014faf8876b.zip | |
feat: add new binary for just toggling frames
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | justfile | 12 | ||||
| -rw-r--r-- | src/bin/zjframes.rs | 197 | ||||
| -rw-r--r-- | tests/zjframes/config.kdl | 414 | ||||
| -rw-r--r-- | tests/zjframes/layout.kdl | 9 | ||||
| -rw-r--r-- | tests/zjstatus/layout.kdl (renamed from plugin-dev-workspace.kdl) | 0 |
6 files changed, 634 insertions, 2 deletions
@@ -8,6 +8,10 @@ edition = "2018" name = "zjstatus" bench = false +[[bin]] +name = "zjframes" +bench = false + [lib] bench = false @@ -12,8 +12,16 @@ build: cargo build --features tracing # Build zjstatus with tracing and start a zellij session with the dev layout. -run: build - zellij -n ./plugin-dev-workspace.kdl -s zjstatus-dev +run target="zjstatus": build + #!/usr/bin/env bash + case "{{target}}" in + "zjframes") + zellij -s zjframes-dev --config ./tests/zjframes/config.kdl -n ./tests/zjframes/layout.kdl + ;; + *) + zellij -s zjstatus-dev -n ./tests/zjstatus/layout.kdl + ;; + esac # Watch and run tests with nextest. test: diff --git a/src/bin/zjframes.rs b/src/bin/zjframes.rs new file mode 100644 index 0000000..6f6eda3 --- /dev/null +++ b/src/bin/zjframes.rs @@ -0,0 +1,197 @@ +use zellij_tile::prelude::*; + +use std::{collections::BTreeMap, sync::Arc}; + +use zjstatus::frames; + +#[derive(Default, Debug, Clone)] +pub struct ZellijState { + pub mode: ModeInfo, + pub panes: PaneManifest, + pub tabs: Vec<TabInfo>, +} + +#[derive(Default)] +struct State { + pending_events: Vec<Event>, + got_permissions: bool, + state: ZellijState, + + hide_frame_for_single_pane: bool, + hide_frame_except_for_search: bool, + hide_frame_except_for_fullscreen: bool, + + err: Option<anyhow::Error>, +} + +#[cfg(not(test))] +register_plugin!(State); + +#[cfg(feature = "tracing")] +fn init_tracing() { + use std::fs::File; + use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + + let file = File::create("/host/.zjstatus.log"); + let file = match file { + Ok(file) => file, + Err(error) => panic!("Error: {:?}", error), + }; + let debug_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file)); + + tracing_subscriber::registry().with(debug_log).init(); + + tracing::info!("tracing initialized"); +} + +impl ZellijPlugin for State { + fn load(&mut self, configuration: BTreeMap<String, String>) { + #[cfg(feature = "tracing")] + init_tracing(); + + // we need the ReadApplicationState permission to receive the ModeUpdate and TabUpdate + // events + // we need the RunCommands permission to run "cargo test" in a floating window + request_permission(&[ + PermissionType::ReadApplicationState, + PermissionType::ChangeApplicationState, + ]); + + subscribe(&[ + EventType::ModeUpdate, + EventType::PaneUpdate, + EventType::PermissionRequestResult, + EventType::TabUpdate, + EventType::SessionUpdate, + ]); + + self.hide_frame_for_single_pane = match configuration.get("hide_frame_for_single_pane") { + Some(toggle) => toggle == "true", + None => false, + }; + self.hide_frame_except_for_search = match configuration.get("hide_frame_except_for_search") + { + Some(toggle) => toggle == "true", + None => false, + }; + self.hide_frame_except_for_fullscreen = + match configuration.get("hide_frame_except_for_fullscreen") { + Some(toggle) => toggle == "true", + None => false, + }; + + self.pending_events = Vec::new(); + self.got_permissions = false; + self.state = ZellijState::default(); + } + + #[tracing::instrument(skip_all, fields(event_type))] + fn update(&mut self, event: Event) -> bool { + if let Event::PermissionRequestResult(PermissionStatus::Granted) = event { + self.got_permissions = true; + + while !self.pending_events.is_empty() { + tracing::debug!("processing cached event"); + let ev = self.pending_events.pop(); + + self.handle_event(ev.unwrap()); + } + } + + if !self.got_permissions { + tracing::debug!("caching event"); + self.pending_events.push(event); + + return false; + } + + self.handle_event(event) + } + + #[tracing::instrument(skip_all)] + fn render(&mut self, _rows: usize, _cols: usize) { + if !self.got_permissions { + return; + } + + if let Some(err) = &self.err { + println!("Error: {:?}", err); + + return; + } + + print!("Please load this plugin in the background"); + } +} + +impl State { + fn handle_event(&mut self, event: Event) -> bool { + let mut should_render = false; + match event { + Event::ModeUpdate(mode_info) => { + tracing::Span::current().record("event_type", "Event::ModeUpdate"); + tracing::debug!(mode = ?mode_info.mode); + tracing::debug!(mode = ?mode_info.session_name); + + self.state.mode = mode_info; + + frames::hide_frames_conditionally( + self.hide_frame_for_single_pane, + self.hide_frame_except_for_search, + self.hide_frame_except_for_fullscreen, + &self.state.tabs, + &self.state.panes, + &self.state.mode, + get_plugin_ids(), + ); + } + Event::PaneUpdate(pane_info) => { + tracing::Span::current().record("event_type", "Event::PaneUpdate"); + tracing::debug!(pane_count = ?pane_info.panes.len()); + + self.state.panes = pane_info; + + frames::hide_frames_conditionally( + self.hide_frame_for_single_pane, + self.hide_frame_except_for_search, + self.hide_frame_except_for_fullscreen, + &self.state.tabs, + &self.state.panes, + &self.state.mode, + get_plugin_ids(), + ); + } + Event::PermissionRequestResult(result) => { + tracing::Span::current().record("event_type", "Event::PermissionRequestResult"); + tracing::debug!(result = ?result); + set_selectable(false); + should_render = true; + } + Event::SessionUpdate(session_info, _) => { + tracing::Span::current().record("event_type", "Event::SessionUpdate"); + + let current_session = session_info.iter().find(|s| s.is_current_session); + + if let Some(current_session) = current_session { + frames::hide_frames_conditionally( + self.hide_frame_for_single_pane, + self.hide_frame_except_for_search, + self.hide_frame_except_for_fullscreen, + ¤t_session.tabs, + ¤t_session.panes, + &self.state.mode, + get_plugin_ids(), + ); + } + } + Event::TabUpdate(tab_info) => { + tracing::Span::current().record("event_type", "Event::TabUpdate"); + tracing::debug!(tab_count = ?tab_info.len()); + + self.state.tabs = tab_info; + } + _ => (), + }; + should_render + } +} diff --git a/tests/zjframes/config.kdl b/tests/zjframes/config.kdl new file mode 100644 index 0000000..48520e0 --- /dev/null +++ b/tests/zjframes/config.kdl @@ -0,0 +1,414 @@ +// If you'd like to override the default keybindings completely, be sure to change "keybinds" to "keybinds clear-defaults=true" +keybinds { + normal { + // uncomment this and adjust key if using copy_on_select=false + // bind "Alt c" { Copy; } + } + locked { + bind "Ctrl g" { SwitchToMode "Normal"; } + } + resize { + bind "Ctrl n" { SwitchToMode "Normal"; } + bind "h" "Left" { Resize "Increase Left"; } + bind "j" "Down" { Resize "Increase Down"; } + bind "k" "Up" { Resize "Increase Up"; } + bind "l" "Right" { Resize "Increase Right"; } + bind "H" { Resize "Decrease Left"; } + bind "J" { Resize "Decrease Down"; } + bind "K" { Resize "Decrease Up"; } + bind "L" { Resize "Decrease Right"; } + bind "=" "+" { Resize "Increase"; } + bind "-" { Resize "Decrease"; } + } + pane { + bind "Ctrl p" { SwitchToMode "Normal"; } + bind "h" "Left" { MoveFocus "Left"; } + bind "l" "Right" { MoveFocus "Right"; } + bind "j" "Down" { MoveFocus "Down"; } + bind "k" "Up" { MoveFocus "Up"; } + bind "p" { SwitchFocus; } + bind "n" { NewPane; SwitchToMode "Normal"; } + bind "d" { NewPane "Down"; SwitchToMode "Normal"; } + bind "r" { NewPane "Right"; SwitchToMode "Normal"; } + bind "x" { CloseFocus; SwitchToMode "Normal"; } + bind "f" { ToggleFocusFullscreen; SwitchToMode "Normal"; } + bind "z" { TogglePaneFrames; SwitchToMode "Normal"; } + bind "w" { ToggleFloatingPanes; SwitchToMode "Normal"; } + bind "e" { TogglePaneEmbedOrFloating; SwitchToMode "Normal"; } + bind "c" { SwitchToMode "RenamePane"; PaneNameInput 0;} + } + move { + bind "Ctrl h" { SwitchToMode "Normal"; } + bind "n" "Tab" { MovePane; } + bind "p" { MovePaneBackwards; } + bind "h" "Left" { MovePane "Left"; } + bind "j" "Down" { MovePane "Down"; } + bind "k" "Up" { MovePane "Up"; } + bind "l" "Right" { MovePane "Right"; } + } + tab { + bind "Ctrl t" { SwitchToMode "Normal"; } + bind "r" { SwitchToMode "RenameTab"; TabNameInput 0; } + bind "h" "Left" "Up" "k" { GoToPreviousTab; } + bind "l" "Right" "Down" "j" { GoToNextTab; } + bind "n" { NewTab; SwitchToMode "Normal"; } + bind "x" { CloseTab; SwitchToMode "Normal"; } + bind "s" { ToggleActiveSyncTab; SwitchToMode "Normal"; } + bind "b" { BreakPane; SwitchToMode "Normal"; } + bind "]" { BreakPaneRight; SwitchToMode "Normal"; } + bind "[" { BreakPaneLeft; SwitchToMode "Normal"; } + bind "1" { GoToTab 1; SwitchToMode "Normal"; } + bind "2" { GoToTab 2; SwitchToMode "Normal"; } + bind "3" { GoToTab 3; SwitchToMode "Normal"; } + bind "4" { GoToTab 4; SwitchToMode "Normal"; } + bind "5" { GoToTab 5; SwitchToMode "Normal"; } + bind "6" { GoToTab 6; SwitchToMode "Normal"; } + bind "7" { GoToTab 7; SwitchToMode "Normal"; } + bind "8" { GoToTab 8; SwitchToMode "Normal"; } + bind "9" { GoToTab 9; SwitchToMode "Normal"; } + bind "Tab" { ToggleTab; } + } + scroll { + bind "Ctrl s" { SwitchToMode "Normal"; } + bind "e" { EditScrollback; SwitchToMode "Normal"; } + bind "s" { SwitchToMode "EnterSearch"; SearchInput 0; } + bind "Ctrl c" { ScrollToBottom; SwitchToMode "Normal"; } + bind "j" "Down" { ScrollDown; } + bind "k" "Up" { ScrollUp; } + bind "Ctrl f" "PageDown" "Right" "l" { PageScrollDown; } + bind "Ctrl b" "PageUp" "Left" "h" { PageScrollUp; } + bind "d" { HalfPageScrollDown; } + bind "u" { HalfPageScrollUp; } + // uncomment this and adjust key if using copy_on_select=false + // bind "Alt c" { Copy; } + } + search { + bind "Ctrl s" { SwitchToMode "Normal"; } + bind "Ctrl c" { ScrollToBottom; SwitchToMode "Normal"; } + bind "j" "Down" { ScrollDown; } + bind "k" "Up" { ScrollUp; } + bind "Ctrl f" "PageDown" "Right" "l" { PageScrollDown; } + bind "Ctrl b" "PageUp" "Left" "h" { PageScrollUp; } + bind "d" { HalfPageScrollDown; } + bind "u" { HalfPageScrollUp; } + bind "n" { Search "down"; } + bind "p" { Search "up"; } + bind "c" { SearchToggleOption "CaseSensitivity"; } + bind "w" { SearchToggleOption "Wrap"; } + bind "o" { SearchToggleOption "WholeWord"; } + } + entersearch { + bind "Ctrl c" "Esc" { SwitchToMode "Scroll"; } + bind "Enter" { SwitchToMode "Search"; } + } + renametab { + bind "Ctrl c" { SwitchToMode "Normal"; } + bind "Esc" { UndoRenameTab; SwitchToMode "Tab"; } + } + renamepane { + bind "Ctrl c" { SwitchToMode "Normal"; } + bind "Esc" { UndoRenamePane; SwitchToMode "Pane"; } + } + session { + bind "Ctrl o" { SwitchToMode "Normal"; } + bind "Ctrl s" { SwitchToMode "Scroll"; } + bind "d" { Detach; } + bind "w" { + LaunchOrFocusPlugin "session-manager" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } + bind "c" { + LaunchOrFocusPlugin "configuration" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } + bind "p" { + LaunchOrFocusPlugin "plugin-manager" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } + } + tmux { + bind "[" { SwitchToMode "Scroll"; } + bind "Ctrl b" { Write 2; SwitchToMode "Normal"; } + bind "\"" { NewPane "Down"; SwitchToMode "Normal"; } + bind "%" { NewPane "Right"; SwitchToMode "Normal"; } + bind "z" { ToggleFocusFullscreen; SwitchToMode "Normal"; } + bind "c" { NewTab; SwitchToMode "Normal"; } + bind "," { SwitchToMode "RenameTab"; } + bind "p" { GoToPreviousTab; SwitchToMode "Normal"; } + bind "n" { GoToNextTab; SwitchToMode "Normal"; } + bind "Left" { MoveFocus "Left"; SwitchToMode "Normal"; } + bind "Right" { MoveFocus "Right"; SwitchToMode "Normal"; } + bind "Down" { MoveFocus "Down"; SwitchToMode "Normal"; } + bind "Up" { MoveFocus "Up"; SwitchToMode "Normal"; } + bind "h" { MoveFocus "Left"; SwitchToMode "Normal"; } + bind "l" { MoveFocus "Right"; SwitchToMode "Normal"; } + bind "j" { MoveFocus "Down"; SwitchToMode "Normal"; } + bind "k" { MoveFocus "Up"; SwitchToMode "Normal"; } + bind "o" { FocusNextPane; } + bind "d" { Detach; } + bind "Space" { NextSwapLayout; } + bind "x" { CloseFocus; SwitchToMode "Normal"; } + } + shared_except "locked" { + bind "Ctrl g" { SwitchToMode "Locked"; } + bind "Ctrl q" { Quit; } + bind "Alt f" { ToggleFloatingPanes; } + bind "Alt n" { NewPane; } + bind "Alt i" { MoveTab "Left"; } + bind "Alt o" { MoveTab "Right"; } + bind "Alt h" "Alt Left" { MoveFocusOrTab "Left"; } + bind "Alt l" "Alt Right" { MoveFocusOrTab "Right"; } + bind "Alt j" "Alt Down" { MoveFocus "Down"; } + bind "Alt k" "Alt Up" { MoveFocus "Up"; } + bind "Alt =" "Alt +" { Resize "Increase"; } + bind "Alt -" { Resize "Decrease"; } + bind "Alt [" { PreviousSwapLayout; } + bind "Alt ]" { NextSwapLayout; } + } + shared_except "normal" "locked" { + bind "Enter" "Esc" { SwitchToMode "Normal"; } + } + shared_except "pane" "locked" { + bind "Ctrl p" { SwitchToMode "Pane"; } + } + shared_except "resize" "locked" { + bind "Ctrl n" { SwitchToMode "Resize"; } + } + shared_except "scroll" "locked" { + bind "Ctrl s" { SwitchToMode "Scroll"; } + } + shared_except "session" "locked" { + bind "Ctrl o" { SwitchToMode "Session"; } + } + shared_except "tab" "locked" { + bind "Ctrl t" { SwitchToMode "Tab"; } + } + shared_except "move" "locked" { + bind "Ctrl h" { SwitchToMode "Move"; } + } + shared_except "tmux" "locked" { + bind "Ctrl b" { SwitchToMode "Tmux"; } + } +} + +// Plugin aliases - can be used to change the implementation of Zellij +// changing these requires a restart to take effect +plugins { + tab-bar location="zellij:tab-bar" + status-bar location="zellij:status-bar" + strider location="zellij:strider" + compact-bar location="zellij:compact-bar" + session-manager location="zellij:session-manager" + welcome-screen location="zellij:session-manager" { + welcome_screen true + } + filepicker location="zellij:strider" { + cwd "/" + } + configuration location="zellij:configuration" + plugin-manager location="zellij:plugin-manager" +} + +// Plugins to load in the background when a new session starts +load_plugins { + "file:./target/wasm32-wasip1/debug/zjframes.wasm" { + hide_frame_for_single_pane "false" + hide_frame_except_for_search "true" + hide_frame_except_for_fullscreen "true" + } + // "file:/path/to/my-plugin.wasm" + // "https://example.com/my-plugin.wasm" +} + +// Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP +// eg. when terminal window with an active zellij session is closed +// (Requires restart) +// Options: +// - detach (Default) +// - quit +// +// on_force_close "quit" + +// Send a request for a simplified ui (without arrow fonts) to plugins +// Options: +// - true +// - false (Default) +// +// simplified_ui true + +// Choose the path to the default shell that zellij will use for opening new panes +// Default: $SHELL +// +// default_shell "fish" + +// Choose the path to override cwd that zellij will use for opening new panes +// +// default_cwd "" + +// Toggle between having pane frames around the panes +// Options: +// - true (default) +// - false +// +// pane_frames true + +// Toggle between having Zellij lay out panes according to a predefined set of layouts whenever possible +// Options: +// - true (default) +// - false +// +// auto_layout true + +// Whether sessions should be serialized to the cache folder (including their tabs/panes, cwds and running commands) so that they can later be resurrected +// (Requires restart) +// Options: +// - true (default) +// - false +// +// session_serialization false + +// Whether pane viewports are serialized along with the session, default is false +// (Requires restart) +// Options: +// - true +// - false (default) +// +// serialize_pane_viewport true + +// Scrollback lines to serialize along with the pane viewport when serializing sessions, 0 +// defaults to the scrollback size. If this number is higher than the scrollback size, it will +// also default to the scrollback size. This does nothing if `serialize_pane_viewport` is not true. +// (Requires restart) +// +// scrollback_lines_to_serialize 10000 + +// Define color themes for Zellij +// For more examples, see: https://github.com/zellij-org/zellij/tree/main/example/themes +// Once these themes are defined, one of them should to be selected in the "theme" section of this file +// +// themes { +// dracula { +// fg 248 248 242 +// bg 40 42 54 +// red 255 85 85 +// green 80 250 123 +// yellow 241 250 140 +// blue 98 114 164 +// magenta 255 121 198 +// orange 255 184 108 +// cyan 139 233 253 +// black 0 0 0 +// white 255 255 255 +// } +// } + +// Choose the theme that is specified in the themes section. +// Default: default +// +// theme "default" + +// The name of the default layout to load on startup +// Default: "default" +// (Requires restart) +// +// default_layout "compact" + +// Choose the mode that zellij uses when starting up. +// Default: normal +// +// default_mode "locked" + +// Toggle enabling the mouse mode. +// On certain configurations, or terminals this could +// potentially interfere with copying text. +// (Requires restart) +// Options: +// - true (default) +// - false +// +// mouse_mode false + +// Configure the scroll back buffer size +// This is the number of lines zellij stores for each pane in the scroll back +// buffer. Excess number of lines are discarded in a FIFO fashion. +// (Requires restart) +// Valid values: positive integers +// Default value: 10000 +// +// scroll_buffer_size 10000 + +// Provide a command to execute when copying text. The text will be piped to +// the stdin of the program to perform the copy. This can be used with +// terminal emulators which do not support the OSC 52 ANSI control sequence +// that will be used by default if this option is not set. +// Examples: +// +// copy_command "xclip -selection clipboard" // x11 +// copy_command "wl-copy" // wayland +// copy_command "pbcopy" // osx + +// Choose the destination for copied text +// Allows using the primary selection buffer (on x11/wayland) instead of the system clipboard. +// Does not apply when using copy_command. +// Options: +// - system (default) +// - primary +// +// copy_clipboard "primary" + +// Enable or disable automatic copy (and clear) of selection when releasing mouse +// Default: true +// +// copy_on_select false + +// Path to the default editor to use to edit pane scrollbuffer +// Default: $EDITOR or $VISUAL +// +// scrollback_editor "/usr/bin/vim" + +// When attaching to an existing session with other users, +// should the session be mirrored (true) +// or should each user have their own cursor (false) +// (Requires restart) +// Default: false +// +// mirror_session true + +// The folder in which Zellij will look for layouts +// (Requires restart) +// +// layout_dir "/path/to/my/layout_dir" + +// The folder in which Zellij will look for themes +// (Requires restart) +// +// theme_dir "/path/to/my/theme_dir" + +// Enable or disable the rendering of styled and colored underlines (undercurl). +// May need to be disabled for certain unsupported terminals +// (Requires restart) +// Default: true +// +// styled_underlines false + +// Enable or disable writing of session metadata to disk (if disabled, other sessions might not know +// metadata info on this session) +// (Requires restart) +// Default: false +// +// disable_session_metadata true + +// Enable or disable support for the enhanced Kitty Keyboard Protocol (the host terminal must also support it) +// (Requires restart) +// Default: true (if the host terminal supports it) +// +// support_kitty_keyboard_protocol false diff --git a/tests/zjframes/layout.kdl b/tests/zjframes/layout.kdl new file mode 100644 index 0000000..8ce2ddf --- /dev/null +++ b/tests/zjframes/layout.kdl @@ -0,0 +1,9 @@ +layout { + pane size=1 borderless=true { + plugin location="tab-bar" + } + pane + pane size=1 borderless=true { + plugin location="status-bar" + } +} diff --git a/plugin-dev-workspace.kdl b/tests/zjstatus/layout.kdl index 4af6fe3..4af6fe3 100644 --- a/plugin-dev-workspace.kdl +++ b/tests/zjstatus/layout.kdl |
