diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-26 15:30:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 15:30:15 +0100 |
commit | 21273ac95a2fed6b07d8550fe2d4f65993be7037 (patch) | |
tree | f5a7aa488ece8f21c17350bb3ec14ceaf15f60a7 /zellij-utils | |
parent | 27bffbf1533b4b2d3c10b1305557c75ddd121374 (diff) |
feat(plugins): introduce plugin aliases (#3157)
* working prototype with passing tests
* new tests and passing plugin tests as well
* style(code): cleanups
* cleanup strider from unused search feature
* prototype of removing old plugin block from the config
* aliases working from config file and all tests passing
* fixups and cleanups
* use aliases in layouts
* update test snapshot
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils')
29 files changed, 1217 insertions, 1044 deletions
diff --git a/zellij-utils/assets/config/default.kdl b/zellij-utils/assets/config/default.kdl index f8dc9a756..c8e61bf43 100644 --- a/zellij-utils/assets/config/default.kdl +++ b/zellij-utils/assets/config/default.kdl @@ -186,11 +186,15 @@ keybinds { } plugins { - tab-bar { path "tab-bar"; } - status-bar { path "status-bar"; } - strider { path "strider"; } - compact-bar { path "compact-bar"; } - session-manager { path "session-manager"; } + 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" } // Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP diff --git a/zellij-utils/assets/layouts/compact.kdl b/zellij-utils/assets/layouts/compact.kdl index 7871ad40d..0ac57ee34 100644 --- a/zellij-utils/assets/layouts/compact.kdl +++ b/zellij-utils/assets/layouts/compact.kdl @@ -1,6 +1,6 @@ layout { pane pane size=1 borderless=true { - plugin location="zellij:compact-bar" + plugin location="compact-bar" } } diff --git a/zellij-utils/assets/layouts/compact.swap.kdl b/zellij-utils/assets/layouts/compact.swap.kdl index 923a117c1..300b4bdf7 100644 --- a/zellij-utils/assets/layouts/compact.swap.kdl +++ b/zellij-utils/assets/layouts/compact.swap.kdl @@ -1,7 +1,7 @@ tab_template name="ui" { children pane size=1 borderless=true { - plugin location="zellij:compact-bar" + plugin location="compact-bar" } } diff --git a/zellij-utils/assets/layouts/default.kdl b/zellij-utils/assets/layouts/default.kdl index 4434b29b1..460aee8a2 100644 --- a/zellij-utils/assets/layouts/default.kdl +++ b/zellij-utils/assets/layouts/default.kdl @@ -1,9 +1,9 @@ layout { pane size=1 borderless=true { - plugin location="zellij:tab-bar" + plugin location="tab-bar" } pane pane size=2 borderless=true { - plugin location="zellij:status-bar" + plugin location="status-bar" } } diff --git a/zellij-utils/assets/layouts/default.swap.kdl b/zellij-utils/assets/layouts/default.swap.kdl index 6d5cdb552..71a6dfe95 100644 --- a/zellij-utils/assets/layouts/default.swap.kdl +++ b/zellij-utils/assets/layouts/default.swap.kdl @@ -1,10 +1,10 @@ tab_template name="ui" { pane size=1 borderless=true { - plugin location="zellij:tab-bar" + plugin location="tab-bar" } children pane size=2 borderless=true { - plugin location="zellij:status-bar" + plugin location="status-bar" } } diff --git a/zellij-utils/assets/layouts/disable-status-bar.kdl b/zellij-utils/assets/layouts/disable-status-bar.kdl index 5eca5b0c3..36a194e71 100644 --- a/zellij-utils/assets/layouts/disable-status-bar.kdl +++ b/zellij-utils/assets/layouts/disable-status-bar.kdl @@ -1,6 +1,6 @@ layout { pane size=1 borderless=true { - plugin location="zellij:tab-bar" + plugin location="tab-bar" } pane } diff --git a/zellij-utils/assets/layouts/strider.kdl b/zellij-utils/assets/layouts/strider.kdl index 57ec01a7d..966000618 100644 --- a/zellij-utils/assets/layouts/strider.kdl +++ b/zellij-utils/assets/layouts/strider.kdl @@ -1,14 +1,14 @@ layout { pane size=1 borderless=true { - plugin location="zellij:tab-bar" + plugin location="tab-bar" } pane split_direction="Vertical" { pane size="20%" { - plugin location="zellij:strider" + plugin location="strider" } pane } pane size=2 borderless=true { - plugin location="zellij:status-bar" + plugin location="status-bar" } } diff --git a/zellij-utils/assets/layouts/strider.swap.kdl b/zellij-utils/assets/layouts/strider.swap.kdl index 579fcc8e9..b53444ff0 100644 --- a/zellij-utils/assets/layouts/strider.swap.kdl +++ b/zellij-utils/assets/layouts/strider.swap.kdl @@ -1,10 +1,10 @@ tab_template name="ui" { pane size=1 borderless=true { - plugin location="zellij:tab-bar" + plugin location="tab-bar" } pane split_direction="Vertical" { pane size="20%" { - plugin location="zellij:strider" + plugin location="strider" } pane { children @@ -12,7 +12,7 @@ tab_template name="ui" { } pane size=2 borderless=true { - plugin location="zellij:status-bar" + plugin location="status-bar" } } diff --git a/zellij-utils/assets/layouts/welcome.kdl b/zellij-utils/assets/layouts/welcome.kdl index 1884fe1f0..0ee72ce04 100644 --- a/zellij-utils/assets/layouts/welcome.kdl +++ b/zellij-utils/assets/layouts/welcome.kdl @@ -1,8 +1,6 @@ layout { pane borderless=true { - plugin location="zellij:session-manager" { - welcome_screen true - } + plugin location="welcome-screen" } } session_serialization false // this will apply only to the initial welcome screen layout, and is intended to prevent lots of garbage sessions left around diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index 595293f4e..e5b65d394 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -627,7 +627,7 @@ pub enum CliAction { in_place: bool, #[clap(short, long, value_parser)] move_to_focused_tab: bool, - url: Url, + url: String, #[clap(short, long, value_parser)] configuration: Option<PluginUserConfiguration>, #[clap(short, long, value_parser)] diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index b19529e48..18ed0a8da 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -2,8 +2,8 @@ use super::command::RunCommandAction; use super::layout::{ - FloatingPaneLayout, Layout, RunPlugin, RunPluginLocation, SwapFloatingLayout, SwapTiledLayout, - TiledPaneLayout, + FloatingPaneLayout, Layout, PluginAlias, RunPlugin, RunPluginLocation, RunPluginOrAlias, + SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout, }; use crate::cli::CliAction; use crate::data::{Direction, Resize}; @@ -217,9 +217,9 @@ pub enum Action { LeftClick(Position), RightClick(Position), MiddleClick(Position), - LaunchOrFocusPlugin(RunPlugin, bool, bool, bool, bool), // bools => should float, + LaunchOrFocusPlugin(RunPluginOrAlias, bool, bool, bool, bool), // bools => should float, // move_to_focused_tab, should_open_in_place, skip_cache - LaunchPlugin(RunPlugin, bool, bool, bool, Option<PathBuf>), // bools => should float, + LaunchPlugin(RunPluginOrAlias, bool, bool, bool, Option<PathBuf>), // bools => should float, // should_open_in_place, skip_cache, Option<PathBuf> is cwd LeftMouseRelease(Position), RightMouseRelease(Position), @@ -246,19 +246,19 @@ pub enum Action { /// Query all tab names QueryTabNames, /// Open a new tiled (embedded, non-floating) plugin pane - NewTiledPluginPane(RunPlugin, Option<String>, bool, Option<PathBuf>), // String is an optional name, bool is + NewTiledPluginPane(RunPluginOrAlias, Option<String>, bool, Option<PathBuf>), // String is an optional name, bool is // skip_cache, Option<PathBuf> is cwd NewFloatingPluginPane( - RunPlugin, + RunPluginOrAlias, Option<String>, bool, Option<PathBuf>, Option<FloatingPaneCoordinates>, ), // String is an optional name, bool is // skip_cache, Option<PathBuf> is cwd - NewInPlacePluginPane(RunPlugin, Option<String>, bool), // String is an optional name, bool is + NewInPlacePluginPane(RunPluginOrAlias, Option<String>, bool), // String is an optional name, bool is // skip_cache - StartOrReloadPlugin(RunPlugin), + StartOrReloadPlugin(RunPluginOrAlias), CloseTerminalPane(u32), ClosePluginPane(u32), FocusTerminalPaneWithId(u32, bool), // bool is should_float_if_hidden @@ -351,14 +351,20 @@ impl Action { let cwd = cwd .map(|cwd| current_dir.join(cwd)) .or_else(|| Some(current_dir)); - let user_configuration = configuration.unwrap_or_default(); if let Some(plugin) = plugin { - let location = RunPluginLocation::parse(&plugin, cwd.clone()) - .map_err(|e| format!("Failed to parse plugin loction {plugin}: {}", e))?; - let plugin = RunPlugin { - _allow_exec_host_cmd: false, - location, - configuration: user_configuration, + let plugin = match RunPluginLocation::parse(&plugin, cwd.clone()) { + Ok(location) => { + let user_configuration = configuration.unwrap_or_default(); + RunPluginOrAlias::RunPlugin(RunPlugin { + _allow_exec_host_cmd: false, + location, + configuration: user_configuration, + }) + }, + Err(_) => RunPluginOrAlias::Alias(PluginAlias::new( + &plugin, + &configuration.map(|c| c.inner().clone()), + )), }; if floating { Ok(vec![Action::NewFloatingPluginPane( @@ -571,14 +577,13 @@ impl Action { CliAction::QueryTabNames => Ok(vec![Action::QueryTabNames]), CliAction::StartOrReloadPlugin { url, configuration } => { let current_dir = get_current_dir(); - let run_plugin_location = RunPluginLocation::parse(&url, Some(current_dir)) - .map_err(|e| format!("Failed to parse plugin location: {}", e))?; - let run_plugin = RunPlugin { - location: run_plugin_location, - _allow_exec_host_cmd: false, - configuration: configuration.unwrap_or_default(), - }; - Ok(vec![Action::StartOrReloadPlugin(run_plugin)]) + let run_plugin_or_alias = RunPluginOrAlias::from_url( + &url, + &configuration.map(|c| c.inner().clone()), + None, + Some(current_dir), + )?; + Ok(vec![Action::StartOrReloadPlugin(run_plugin_or_alias)]) }, CliAction::LaunchOrFocusPlugin { url, @@ -589,15 +594,14 @@ impl Action { skip_plugin_cache, } => { let current_dir = get_current_dir(); - let run_plugin_location = RunPluginLocation::parse(url.as_str(), Some(current_dir)) - .map_err(|e| format!("Failed to parse plugin location: {}", e))?; - let run_plugin = RunPlugin { - location: run_plugin_location, - _allow_exec_host_cmd: false, - configuration: configuration.unwrap_or_default(), - }; + let run_plugin_or_alias = RunPluginOrAlias::from_url( + url.as_str(), + &configuration.map(|c| c.inner().clone()), + None, + Some(current_dir), + )?; Ok(vec![Action::LaunchOrFocusPlugin( - run_plugin, + run_plugin_or_alias, floating, move_to_focused_tab, in_place, @@ -612,16 +616,14 @@ impl Action { skip_plugin_cache, } => { let current_dir = get_current_dir(); - let run_plugin_location = - RunPluginLocation::parse(url.as_str(), Some(current_dir.clone())) - .map_err(|e| format!("Failed to parse plugin location: {}", e))?; - let run_plugin = RunPlugin { - location: run_plugin_location, - _allow_exec_host_cmd: false, - configuration: configuration.unwrap_or_default(), - }; + let run_plugin_or_alias = RunPluginOrAlias::from_url( + &url.as_str(), + &configuration.map(|c| c.inner().clone()), + None, + Some(current_dir.clone()), + )?; Ok(vec![Action::LaunchPlugin( - run_plugin, + run_plugin_or_alias, floating, in_place, skip_plugin_cache, diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index eb8fe521d..cf6620a9c 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -9,7 +9,7 @@ use std::convert::TryFrom; use super::keybinds::Keybinds; use super::options::Options; -use super::plugins::{PluginsConfig, PluginsConfigError}; +use super::plugins::{PluginAliases, PluginsConfigError}; use super::theme::{Themes, UiConfig}; use crate::cli::{CliArgs, Command}; use crate::envs::EnvironmentVariables; @@ -25,7 +25,7 @@ pub struct Config { pub keybinds: Keybinds, pub options: Options, pub themes: Themes, - pub plugins: PluginsConfig, + pub plugins: PluginAliases, pub ui: UiConfig, pub env: EnvironmentVariables, } @@ -226,7 +226,7 @@ impl Config { self.options = self.options.merge(other.options); self.keybinds.merge(other.keybinds.clone()); self.themes = self.themes.merge(other.themes); - self.plugins = self.plugins.merge(other.plugins); + self.plugins.merge(other.plugins); self.ui = self.ui.merge(other.ui); self.env = self.env.merge(other.env); Ok(()) @@ -237,11 +237,11 @@ impl Config { mod config_test { use super::*; use crate::data::{InputMode, Palette, PaletteColor, PluginTag}; - use crate::input::layout::RunPluginLocation; + use crate::input::layout::{RunPlugin, RunPluginLocation}; use crate::input::options::{Clipboard, OnForceClose}; - use crate::input::plugins::{PluginConfig, PluginType, PluginsConfig}; + use crate::input::plugins::{PluginConfig, PluginType}; use crate::input::theme::{FrameConfig, Theme, Themes, UiConfig}; - use std::collections::HashMap; + use std::collections::{BTreeMap, HashMap}; use std::io::Write; use tempfile::tempdir; @@ -591,60 +591,54 @@ mod config_test { fn can_define_plugin_configuration_in_configfile() { let config_contents = r#" plugins { - tab-bar { path "tab-bar"; } - status-bar { path "status-bar"; } - strider { - path "strider" - _allow_exec_host_cmd true + 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 } - compact-bar { path "compact-bar"; } + filepicker location="zellij:strider" } "#; let config = Config::from_kdl(config_contents, None).unwrap(); - let mut expected_plugin_configuration = HashMap::new(); + let mut expected_plugin_configuration = BTreeMap::new(); expected_plugin_configuration.insert( - PluginTag::new("tab-bar"), - PluginConfig { - path: PathBuf::from("tab-bar"), - run: PluginType::Pane(None), - location: RunPluginLocation::Zellij(PluginTag::new("tab-bar")), - _allow_exec_host_cmd: false, - userspace_configuration: Default::default(), - }, + "tab-bar".to_owned(), + RunPlugin::from_url("zellij:tab-bar").unwrap(), ); expected_plugin_configuration.insert( - PluginTag::new("status-bar"), - PluginConfig { - path: PathBuf::from("status-bar"), - run: PluginType::Pane(None), - location: RunPluginLocation::Zellij(PluginTag::new("status-bar")), - _allow_exec_host_cmd: false, - userspace_configuration: Default::default(), - }, + "status-bar".to_owned(), + RunPlugin::from_url("zellij:status-bar").unwrap(), ); expected_plugin_configuration.insert( - PluginTag::new("strider"), - PluginConfig { - path: PathBuf::from("strider"), - run: PluginType::Pane(None), - location: RunPluginLocation::Zellij(PluginTag::new("strider")), - _allow_exec_host_cmd: true, - userspace_configuration: Default::default(), - }, + "strider".to_owned(), + RunPlugin::from_url("zellij:strider").unwrap(), ); expected_plugin_configuration.insert( - PluginTag::new("compact-bar"), - |