diff options
Diffstat (limited to 'zellij-utils')
24 files changed, 943 insertions, 163 deletions
diff --git a/zellij-utils/assets/config/default.kdl b/zellij-utils/assets/config/default.kdl index e830cd09f..95f42fe45 100644 --- a/zellij-utils/assets/config/default.kdl +++ b/zellij-utils/assets/config/default.kdl @@ -120,6 +120,13 @@ keybinds { }; SwitchToMode "Normal" } + bind "c" { + LaunchOrFocusPlugin "configuration" { + floating true + move_to_focused_tab true + }; + SwitchToMode "Normal" + } } tmux { bind "[" { SwitchToMode "Scroll"; } @@ -147,6 +154,7 @@ keybinds { 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"; } @@ -197,6 +205,7 @@ plugins { filepicker location="zellij:strider" { cwd "/" } + configuration location="zellij:configuration" } // Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP diff --git a/zellij-utils/assets/plugins/configuration.wasm b/zellij-utils/assets/plugins/configuration.wasm Binary files differnew file mode 100755 index 000000000..581dbfb18 --- /dev/null +++ b/zellij-utils/assets/plugins/configuration.wasm diff --git a/zellij-utils/assets/prost/api.plugin_command.rs b/zellij-utils/assets/prost/api.plugin_command.rs index 393f2e0c1..1e57602e4 100644 --- a/zellij-utils/assets/prost/api.plugin_command.rs +++ b/zellij-utils/assets/prost/api.plugin_command.rs @@ -119,7 +119,7 @@ pub mod plugin_command { #[prost(message, tag = "62")] NewTabsWithLayoutInfoPayload(super::NewTabsWithLayoutInfoPayload), #[prost(string, tag = "63")] - RebindKeysPayload(::prost::alloc::string::String), + ReconfigurePayload(::prost::alloc::string::String), } } #[allow(clippy::derive_partial_eq_without_eq)] @@ -433,7 +433,7 @@ pub enum CommandName { DumpSessionLayout = 84, CloseSelf = 85, NewTabsWithLayoutInfo = 86, - RebindKeys = 87, + Reconfigure = 87, } impl CommandName { /// String value of the enum field names used in the ProtoBuf definition. @@ -529,7 +529,7 @@ impl CommandName { CommandName::DumpSessionLayout => "DumpSessionLayout", CommandName::CloseSelf => "CloseSelf", CommandName::NewTabsWithLayoutInfo => "NewTabsWithLayoutInfo", - CommandName::RebindKeys => "RebindKeys", + CommandName::Reconfigure => "Reconfigure", } } /// Creates an enum from field names used in the ProtoBuf definition. @@ -622,7 +622,7 @@ impl CommandName { "DumpSessionLayout" => Some(Self::DumpSessionLayout), "CloseSelf" => Some(Self::CloseSelf), "NewTabsWithLayoutInfo" => Some(Self::NewTabsWithLayoutInfo), - "RebindKeys" => Some(Self::RebindKeys), + "Reconfigure" => Some(Self::Reconfigure), _ => None, } } diff --git a/zellij-utils/assets/prost/api.plugin_permission.rs b/zellij-utils/assets/prost/api.plugin_permission.rs index 50bc853fa..013732d9b 100644 --- a/zellij-utils/assets/prost/api.plugin_permission.rs +++ b/zellij-utils/assets/prost/api.plugin_permission.rs @@ -10,7 +10,7 @@ pub enum PermissionType { WebAccess = 6, ReadCliPipes = 7, MessageAndLaunchOtherPlugins = 8, - RebindKeys = 9, + Reconfigure = 9, } impl PermissionType { /// String value of the enum field names used in the ProtoBuf definition. @@ -30,7 +30,7 @@ impl PermissionType { PermissionType::MessageAndLaunchOtherPlugins => { "MessageAndLaunchOtherPlugins" } - PermissionType::RebindKeys => "RebindKeys", + PermissionType::Reconfigure => "Reconfigure", } } /// Creates an enum from field names used in the ProtoBuf definition. @@ -45,7 +45,7 @@ impl PermissionType { "WebAccess" => Some(Self::WebAccess), "ReadCliPipes" => Some(Self::ReadCliPipes), "MessageAndLaunchOtherPlugins" => Some(Self::MessageAndLaunchOtherPlugins), - "RebindKeys" => Some(Self::RebindKeys), + "Reconfigure" => Some(Self::Reconfigure), _ => None, } } diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs index 05794495a..1c11815c8 100644 --- a/zellij-utils/src/consts.rs +++ b/zellij-utils/src/consts.rs @@ -110,6 +110,7 @@ mod not_wasm { add_plugin!(assets, "tab-bar.wasm"); add_plugin!(assets, "strider.wasm"); add_plugin!(assets, "session-manager.wasm"); + add_plugin!(assets, "configuration.wasm"); assets }; } diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index c7ebb300d..0ebb6f1be 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -288,6 +288,33 @@ impl BareKey { Ok("57361") => Some(BareKey::PrintScreen), Ok("57362") => Some(BareKey::Pause), Ok("57363") => Some(BareKey::Menu), + Ok("57399") => Some(BareKey::Char('0')), + Ok("57400") => Some(BareKey::Char('1')), + Ok("57401") => Some(BareKey::Char('2')), + Ok("57402") => Some(BareKey::Char('3')), + Ok("57403") => Some(BareKey::Char('4')), + Ok("57404") => Some(BareKey::Char('5')), + Ok("57405") => Some(BareKey::Char('6')), + Ok("57406") => Some(BareKey::Char('7')), + Ok("57407") => Some(BareKey::Char('8')), + Ok("57408") => Some(BareKey::Char('9')), + Ok("57409") => Some(BareKey::Char('.')), + Ok("57410") => Some(BareKey::Char('/')), + Ok("57411") => Some(BareKey::Char('*')), + Ok("57412") => Some(BareKey::Char('-')), + Ok("57413") => Some(BareKey::Char('+')), + Ok("57414") => Some(BareKey::Enter), + Ok("57415") => Some(BareKey::Char('=')), + Ok("57417") => Some(BareKey::Left), + Ok("57418") => Some(BareKey::Right), + Ok("57419") => Some(BareKey::Up), + Ok("57420") => Some(BareKey::Down), + Ok("57421") => Some(BareKey::PageUp), + Ok("57422") => Some(BareKey::PageDown), + Ok("57423") => Some(BareKey::Home), + Ok("57424") => Some(BareKey::End), + Ok("57425") => Some(BareKey::Insert), + Ok("57426") => Some(BareKey::Delete), Ok(num) => u8::from_str_radix(num, 10) .ok() .map(|n| BareKey::Char((n as char).to_ascii_lowercase())), @@ -915,7 +942,7 @@ pub enum Permission { WebAccess, ReadCliPipes, MessageAndLaunchOtherPlugins, - RebindKeys, + Reconfigure, } impl PermissionType { @@ -936,7 +963,7 @@ impl PermissionType { PermissionType::MessageAndLaunchOtherPlugins => { "Send messages to and launch other plugins".to_owned() }, - PermissionType::RebindKeys => "Rebind keys".to_owned(), + PermissionType::Reconfigure => "Change Zellij runtime configuration".to_owned(), } } } @@ -1137,6 +1164,9 @@ impl ModeInfo { pub fn update_keybinds(&mut self, keybinds: Keybinds) { self.keybinds = keybinds.to_keybinds_vec(); } + pub fn update_default_mode(&mut self, new_default_mode: InputMode) { + self.base_mode = Some(new_default_mode); + } } #[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)] @@ -1154,6 +1184,7 @@ pub enum LayoutInfo { BuiltIn(String), File(String), Url(String), + Stringified(String), } impl LayoutInfo { @@ -1162,6 +1193,7 @@ impl LayoutInfo { LayoutInfo::BuiltIn(name) => &name, LayoutInfo::File(name) => &name, LayoutInfo::Url(url) => &url, + LayoutInfo::Stringified(layout) => &layout, } } pub fn is_builtin(&self) -> bool { @@ -1169,6 +1201,7 @@ impl LayoutInfo { LayoutInfo::BuiltIn(_name) => true, LayoutInfo::File(_name) => false, LayoutInfo::Url(_url) => false, + LayoutInfo::Stringified(_stringified) => false, } } } @@ -1740,5 +1773,5 @@ pub enum PluginCommand { DumpSessionLayout, CloseSelf, NewTabsWithLayoutInfo(LayoutInfo), - RebindKeys(String), // String -> stringified keybindings + Reconfigure(String), // String -> stringified configuration } diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 3656d8ade..8700dd15e 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -353,7 +353,7 @@ pub enum ScreenContext { RenameSession, DumpLayoutToPlugin, ListClientsMetadata, - RebindKeys, + Reconfigure, } /// Stack call representations corresponding to the different types of [`PtyInstruction`]s. @@ -409,6 +409,7 @@ pub enum PluginContext { KeybindPipe, DumpLayoutToPlugin, ListClientsMetadata, + Reconfigure, } /// Stack call representations corresponding to the different types of [`ClientInstruction`]s. @@ -457,7 +458,7 @@ pub enum ServerContext { DisconnectAllClientsExcept, ChangeMode, ChangeModeForAllClients, - RebindKeys, + Reconfigure, } #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 5d6d99dea..32a8a8288 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -712,16 +712,6 @@ impl Action { pub fn launches_plugin(&self, plugin_url: &str) -> bool { match self { Action::LaunchPlugin(run_plugin_or_alias, ..) => { - log::info!( - "1: {:?} == {:?}", - run_plugin_or_alias.location_string(), - plugin_url - ); - eprintln!( - "1: {:?} == {:?}", - run_plugin_or_alias.location_string(), - plugin_url - ); &run_plugin_or_alias.location_string() == plugin_url }, Action::LaunchOrFocusPlugin(run_plugin_or_alias, ..) => { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 822077250..77411a5de 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -1142,15 +1142,20 @@ impl Layout { let (path_to_raw_layout, raw_layout, raw_swap_layouts) = match layout_info { LayoutInfo::File(layout_name_without_extension) => { let layout_dir = layout_dir.clone().or_else(|| default_layout_dir()); - Self::stringified_from_dir( - &PathBuf::from(layout_name_without_extension), - layout_dir.as_ref(), - )? + let (path_to_layout, stringified_layout, swap_layouts) = + Self::stringified_from_dir( + &PathBuf::from(layout_name_without_extension), + layout_dir.as_ref(), + )?; + (Some(path_to_layout), stringified_layout, swap_layouts) }, LayoutInfo::BuiltIn(layout_name) => { - Self::stringified_from_default_assets(&PathBuf::from(layout_name))? + let (path_to_layout, stringified_layout, swap_layouts) = + Self::stringified_from_default_assets(&PathBuf::from(layout_name))?; + (Some(path_to_layout), stringified_layout, swap_layouts) }, - LayoutInfo::Url(url) => (url.clone(), Self::stringified_from_url(&url)?, None), + LayoutInfo::Url(url) => (Some(url.clone()), Self::stringified_from_url(&url)?, None), + LayoutInfo::Stringified(stringified_layout) => (None, stringified_layout, None), }; Layout::from_kdl( &raw_layout, @@ -1208,7 +1213,7 @@ impl Layout { Layout::stringified_from_path_or_default(layout_path, layout_dir)?; let layout = Layout::from_kdl( &raw_layout, - path_to_raw_layout, + Some(path_to_raw_layout), raw_swap_layouts .as_ref() .map(|(r, f)| (r.as_str(), f.as_str())), @@ -1226,10 +1231,18 @@ impl Layout { Err(e) => Err(ConfigError::DownloadError(format!("{}", e))), } })?; - let layout = Layout::from_kdl(&raw_layout, url.into(), None, None)?; + let layout = Layout::from_kdl(&raw_layout, Some(url.into()), None, None)?; let config = Config::from_kdl(&raw_layout, Some(config))?; // this merges the two config, with Ok((layout, config)) } + pub fn from_stringified_layout( + stringified_layout: &str, + config: Config, + ) -> Result<(Layout, Config), ConfigError> { + let layout = Layout::from_kdl(&stringified_layout, None, None, None)?; + let config = Config::from_kdl(&stringified_layout, Some(config))?; // this merges the two config, with + Ok((layout, config)) + } #[cfg(target_family = "wasm")] pub fn from_url(url: &str, config: Config) -> Result<(Layout, Config), ConfigError> { Err(ConfigError::DownloadError(format!( @@ -1244,7 +1257,7 @@ impl Layout { Layout::stringified_from_path_or_default(layout_path, layout_dir)?; let layout = Layout::from_kdl( &raw_layout, - path_to_raw_layout, + Some(path_to_raw_layout), raw_swap_layouts .as_ref() .map(|(r, f)| (r.as_str(), f.as_str())), @@ -1261,7 +1274,7 @@ impl Layout { Layout::stringified_from_default_assets(layout_name)?; let layout = Layout::from_kdl( &raw_layout, - path_to_raw_layout, + Some(path_to_raw_layout), raw_swap_layouts .as_ref() .map(|(r, f)| (r.as_str(), f.as_str())), @@ -1276,7 +1289,7 @@ impl Layout { swap_layouts: Option<(&str, &str)>, // Option<path_to_swap_layout, stringified_swap_layout> cwd: Option<PathBuf>, ) -> Result<Layout, ConfigError> { - Layout::from_kdl(raw, path_to_raw_layout, swap_layouts, cwd) + Layout::from_kdl(raw, Some(path_to_raw_layout), swap_layouts, cwd) } pub fn stringified_from_dir( layout: &PathBuf, @@ -1498,6 +1511,22 @@ impl Layout { } } } + pub fn pane_count(&self) -> usize { + let mut pane_count = 0; + if let Some((tiled_pane_layout, floating_panes)) = self.template.as_ref() { + pane_count += tiled_pane_layout.pane_count(); + for _ in floating_panes { + pane_count += 1; + } + } + for (_, tiled_pane_layout, floating_panes) in &self.tabs { + pane_count += tiled_pane_layout.pane_count(); + for _ in floating_panes { + pane_count += 1; + } + } + pane_count + } } fn split_space( diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index dd17ac8c2..296b53138 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -33,9 +33,10 @@ mod not_wasm { mode: InputMode, attributes: &ClientAttributes, capabilities: PluginCapabilities, + keybinds: &Keybinds, base_mode: Option<InputMode>, ) -> ModeInfo { - let keybinds = attributes.keybinds.to_keybinds_vec(); + let keybinds = keybinds.to_keybinds_vec(); let session_name = envs::get_session_name().ok(); ModeInfo { diff --git a/zellij-utils/src/input/plugins.rs b/zellij-utils/src/input/plugins.rs index ec68bd59f..5a2ac6451 100644 --- a/zellij-utils/src/input/plugins.rs +++ b/zellij-utils/src/input/plugins.rs @@ -65,6 +65,7 @@ impl PluginConfig { || tag == "compact-bar" || tag == "strider" || tag == "session-manager" + || tag == "configuration" { Some(PluginConfig { path: PathBuf::from(&tag), diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index e2d91c173..d13dd2c08 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -4,7 +4,7 @@ use insta::assert_snapshot; #[test] fn empty_layout() { let kdl_layout = "layout"; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some((TiledPaneLayout::default(), vec![])), ..Default::default() @@ -19,7 +19,7 @@ fn layout_with_one_pane() { pane } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -42,7 +42,7 @@ fn layout_with_multiple_panes() { pane } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -74,7 +74,7 @@ fn layout_with_nested_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -115,7 +115,7 @@ fn layout_with_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout::default(), @@ -159,7 +159,7 @@ fn layout_with_mixed_panes_and_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -186,7 +186,7 @@ fn layout_with_hidden_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { tabs: vec![( None, @@ -218,7 +218,7 @@ fn layout_with_floating_panes_template() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -253,7 +253,7 @@ fn layout_with_shared_tiled_and_floating_panes_template() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -301,7 +301,7 @@ fn layout_with_tabs_and_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); assert_snapshot!(format!("{:#?}", layout)); } @@ -312,7 +312,7 @@ fn layout_with_tabs() { tab } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { tabs: vec![(None, TiledPaneLayout::default(), vec![])], template: Some((TiledPaneLayout::default(), vec![])), @@ -336,7 +336,7 @@ fn layout_with_nested_differing_tabs() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { tabs: vec![ ( @@ -378,7 +378,7 @@ fn layout_with_panes_in_different_mixed_split_sizes() { pane size=2; } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, Some("layout_file_name".into()), None, None).unwrap(); let expected_layout = Layout { template: Some(( TiledPaneLayout { @@ -416,7 +416,7 @@ fn layout_with_command_panes |