diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-23 18:48:33 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2024-02-23 18:48:33 +0100 |
commit | 67ebd1c3c5861102120792b7910df15e84286de2 (patch) | |
tree | eb92b052e82fb6ff716aa09cc23c3c1faf2a9b60 | |
parent | 779baa1e6762ca640ead0a193365e520ff679515 (diff) |
fixups and cleanups
-rw-r--r-- | zellij-utils/src/input/actions.rs | 8 | ||||
-rw-r--r-- | zellij-utils/src/input/config.rs | 119 | ||||
-rw-r--r-- | zellij-utils/src/input/plugins.rs | 5 | ||||
-rw-r--r-- | zellij-utils/src/plugin_api/action.rs | 7 | ||||
-rw-r--r-- | zellij-utils/src/setup.rs | 15 |
5 files changed, 61 insertions, 93 deletions
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index db965747c..0735699ac 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -360,13 +360,7 @@ impl Action { configuration: user_configuration, }) }, - // Err(PluginsConfigError::InvalidUrlScheme(url)) => { - Err(_) => { // TODO: more exact error - RunPluginOrAlias::Alias(PluginAlias::new(&plugin, &configuration.map(|c| c.inner().clone()))) - }, -// Err(e) => { -// return Err(format!("Failed to parse plugin location {plugin}: {}", e)); -// } + Err(_) => RunPluginOrAlias::Alias(PluginAlias::new(&plugin, &configuration.map(|c| c.inner().clone()))), }; if floating { Ok(vec![Action::NewFloatingPluginPane( diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index bde0d3af8..cb17ea537 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -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::{RunPluginLocation, RunPlugin}; use crate::input::options::{Clipboard, OnForceClose}; use crate::input::plugins::{PluginConfig, PluginType}; use crate::input::theme::{FrameConfig, Theme, Themes, UiConfig}; - use std::collections::HashMap; + use std::collections::{HashMap, BTreeMap}; use std::io::Write; use tempfile::tempdir; @@ -587,68 +587,59 @@ mod config_test { assert_eq!(config.themes, expected_themes, "Theme defined in config"); } -// TODO: delete me or adjust me -// #[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 -// } -// compact-bar { path "compact-bar"; } -// } -// "#; -// let config = Config::from_kdl(config_contents, None).unwrap(); -// let mut expected_plugin_configuration = HashMap::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(), -// }, -// ); -// 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(), -// }, -// ); -// 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(), -// }, -// ); -// expected_plugin_configuration.insert( -// PluginTag::new("compact-bar"), -// PluginConfig { -// path: PathBuf::from("compact-bar"), -// run: PluginType::Pane(None), -// location: RunPluginLocation::Zellij(PluginTag::new("compact-bar")), -// _allow_exec_host_cmd: false, -// userspace_configuration: Default::default(), -// }, -// ); -// assert_eq!( -// config.plugins, -// PluginsConfig::from_data(expected_plugin_configuration), -// "Plugins defined in config" -// ); -// } + #[test] + fn can_define_plugin_configuration_in_configfile() { + let config_contents = r#" + 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" + } + "#; + let config = Config::from_kdl(config_contents, None).unwrap(); + let mut expected_plugin_configuration = BTreeMap::new(); + expected_plugin_configuration.insert( + "tab-bar".to_owned(), + RunPlugin::from_url("zellij:tab-bar").unwrap(), + ); + expected_plugin_configuration.insert( + "status-bar".to_owned(), + RunPlugin::from_url("zellij:status-bar").unwrap(), + ); + expected_plugin_configuration.insert( + "strider".to_owned(), + RunPlugin::from_url("zellij:strider").unwrap(), + ); + expected_plugin_configuration.insert( + "compact-bar".to_owned(), + RunPlugin::from_url("zellij:compact-bar").unwrap(), + ); + expected_plugin_configuration.insert( + "session-manager".to_owned(), + RunPlugin::from_url("zellij:session-manager").unwrap(), + ); + let mut welcome_screen_configuration = BTreeMap::new(); + welcome_screen_configuration.insert("welcome_screen".to_owned(), "true".to_owned()); + expected_plugin_configuration.insert( + "welcome-screen".to_owned(), + RunPlugin::from_url("zellij:session-manager").unwrap().with_configuration(welcome_screen_configuration) + ); + expected_plugin_configuration.insert( + "filepicker".to_owned(), + RunPlugin::from_url("zellij:strider").unwrap(), + ); + assert_eq!( + config.plugins, + PluginAliases::from_data(expected_plugin_configuration), + "Plugins defined in config" + ); + } #[test] fn can_define_ui_configuration_in_configfile() { diff --git a/zellij-utils/src/input/plugins.rs b/zellij-utils/src/input/plugins.rs index 4bc6078f1..d198d3fda 100644 --- a/zellij-utils/src/input/plugins.rs +++ b/zellij-utils/src/input/plugins.rs @@ -22,6 +22,11 @@ impl PluginAliases { pub fn merge(&mut self, other: Self) { self.aliases.extend(other.aliases); } + pub fn from_data(aliases: BTreeMap<String, RunPlugin>) -> Self { + PluginAliases { + aliases + } + } } /// Plugin metadata diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs index 62a00a524..e0be33117 100644 --- a/zellij-utils/src/plugin_api/action.rs +++ b/zellij-utils/src/plugin_api/action.rs @@ -1144,13 +1144,6 @@ impl TryFrom<Action> for ProtobufAction { optional_payload: None, }), Action::NewTiledPluginPane(run_plugin, pane_name, skip_plugin_cache, _cwd) => { -// let plugin_url: Url = match run_plugin { -// RunPluginOrAlias::RunPlugin(run_plugin) => Url::from(&run_plugin.location), -// RunPluginOrAlias::Alias(plugin_alias) => { -// // TODO: support plugin alias -// unimplemented!() -// } -// }; Ok(ProtobufAction { name: ProtobufActionName::NewTiledPluginPane as i32, optional_payload: Some(OptionalPayload::NewTiledPluginPanePayload( diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 3b011ddde..d41465872 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -769,21 +769,6 @@ mod setup_test { let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); } -// TODO: delete me or adjust me -// #[test] -// fn layout_plugins_override_config_plugins() { -// let mut cli_args = CliArgs::default(); -// cli_args.config = Some(PathBuf::from(format!( -// "{}/src/test-fixtures/config-with-plugins-config.kdl", -// env!("CARGO_MANIFEST_DIR") -// ))); -// cli_args.layout = Some(PathBuf::from(format!( -// "{}/src/test-fixtures/layout-with-plugins-config.kdl", -// env!("CARGO_MANIFEST_DIR") -// ))); -// let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); -// assert_snapshot!(format!("{:#?}", config)); -// } #[test] fn layout_themes_override_config_themes() { let mut cli_args = CliArgs::default(); |