diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-08-25 12:24:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-25 12:24:43 +0200 |
commit | b44ba85895b4db3a67a0f5c329c62fe120079ff0 (patch) | |
tree | ff34fb572a4ca5e0ff71fc0db9bacb9ef3c56093 /zellij-utils/src | |
parent | 877c467f9f757ca560d77ceef83456c9a50f4917 (diff) |
feat(plugins): optionally move plugin to focused tab (#2725)
* feat(plugins): move_to_focused_tab attribute for LaunchOrFocusPlugin
* style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src')
10 files changed, 36 insertions, 5 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index fd2bdcda7..957a13c1a 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -384,6 +384,8 @@ pub enum CliAction { LaunchOrFocusPlugin { #[clap(short, long, value_parser)] floating: bool, + #[clap(short, long, value_parser)] + move_to_focused_tab: bool, url: Url, #[clap(short, long, value_parser)] configuration: Option<PluginUserConfiguration>, diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index faeb8a4e7..054273a0a 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -204,7 +204,7 @@ pub enum Action { LeftClick(Position), RightClick(Position), MiddleClick(Position), - LaunchOrFocusPlugin(RunPlugin, bool), // bool => should float + LaunchOrFocusPlugin(RunPlugin, bool, bool), // bools => should float, move_to_focused_tab LeftMouseRelease(Position), RightMouseRelease(Position), MiddleMouseRelease(Position), @@ -501,6 +501,7 @@ impl Action { CliAction::LaunchOrFocusPlugin { url, floating, + move_to_focused_tab, configuration, } => { let current_dir = get_current_dir(); @@ -511,7 +512,11 @@ impl Action { _allow_exec_host_cmd: false, configuration: configuration.unwrap_or_default(), }; - Ok(vec![Action::LaunchOrFocusPlugin(run_plugin, floating)]) + Ok(vec![Action::LaunchOrFocusPlugin( + run_plugin, + floating, + move_to_focused_tab, + )]) }, } } diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index af49dbb30..1d09bdac5 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -906,6 +906,9 @@ impl TryFrom<(&KdlNode, &Options)> for Action { let should_float = command_metadata .and_then(|c_m| kdl_child_bool_value_for_entry(c_m, "floating")) .unwrap_or(false); + let move_to_focused_tab = command_metadata + .and_then(|c_m| kdl_child_bool_value_for_entry(c_m, "move_to_focused_tab")) + .unwrap_or(false); let current_dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")); let location = RunPluginLocation::parse(&plugin_path, Some(current_dir))?; let configuration = KdlLayoutParser::parse_plugin_user_configuration(&kdl_action)?; @@ -914,7 +917,11 @@ impl TryFrom<(&KdlNode, &Options)> for Action { _allow_exec_host_cmd: false, configuration, }; - Ok(Action::LaunchOrFocusPlugin(run_plugin, should_float)) + Ok(Action::LaunchOrFocusPlugin( + run_plugin, + should_float, + move_to_focused_tab, + )) }, "PreviousSwapLayout" => Ok(Action::PreviousSwapLayout), "NextSwapLayout" => Ok(Action::NextSwapLayout), diff --git a/zellij-utils/src/plugin_api/action.proto b/zellij-utils/src/plugin_api/action.proto index 05fa5c6ed..429c8432e 100644 --- a/zellij-utils/src/plugin_api/action.proto +++ b/zellij-utils/src/plugin_api/action.proto @@ -84,6 +84,7 @@ message LaunchOrFocusPluginPayload { string plugin_url = 1; bool should_float = 2; optional PluginConfiguration plugin_configuration = 3; + bool move_to_focused_tab = 4; } message GoToTabNamePayload { diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs index 1a964fa9b..b3bff6f84 100644 --- a/zellij-utils/src/plugin_api/action.rs +++ b/zellij-utils/src/plugin_api/action.rs @@ -399,7 +399,12 @@ impl TryFrom<ProtobufAction> for Action { configuration, }; let should_float = payload.should_float; - Ok(Action::LaunchOrFocusPlugin(run_plugin, should_float)) + let move_to_focused_tab = payload.move_to_focused_tab; + Ok(Action::LaunchOrFocusPlugin( + run_plugin, + should_float, + move_to_focused_tab, + )) }, _ => Err("Wrong payload for Action::LaunchOrFocusPlugin"), } @@ -954,7 +959,7 @@ impl TryFrom<Action> for ProtobufAction { optional_payload: Some(OptionalPayload::MiddleClickPayload(position)), }) }, - Action::LaunchOrFocusPlugin(run_plugin, should_float) => { + Action::LaunchOrFocusPlugin(run_plugin, should_float, move_to_focused_tab) => { let url: Url = Url::from(&run_plugin.location); Ok(ProtobufAction { name: ProtobufActionName::LaunchOrFocusPlugin as i32, @@ -962,6 +967,7 @@ impl TryFrom<Action> for ProtobufAction { LaunchOrFocusPluginPayload { plugin_url: url.into(), should_float, + move_to_focused_tab, plugin_configuration: Some(run_plugin.configuration.try_into()?), }, )), diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap index 367866e09..06c90a689 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap @@ -2503,10 +2503,12 @@ Config { configuration: PluginUserConfiguration( { "floating": "true", + "move_to_focused_tab": "true", }, ), }, true, + true, ), SwitchToMode( Normal, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap index 5af23a0a5..b2c4305cb 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap @@ -2503,10 +2503,12 @@ Config { configuration: PluginUserConfiguration( { "floating": "true", + "move_to_focused_tab": "true", }, ), }, true, + true, ), SwitchToMode( Normal, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap index 55173c3ab..42cd12c25 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_plugins_override_config_plugins.snap @@ -2503,10 +2503,12 @@ Config { configuration: PluginUserConfiguration( { "floating": "true", + "move_to_focused_tab": "true", }, ), }, true, + true, ), SwitchToMode( Normal, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap index a7613eee1..9f5749f55 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap @@ -2503,10 +2503,12 @@ Config { configuration: PluginUserConfiguration( { "floating": "true", + "move_to_focused_tab": "true", }, ), }, true, + true, ), SwitchToMode( Normal, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap index dae918163..8da67cf04 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap @@ -2503,10 +2503,12 @@ Config { configuration: PluginUserConfiguration( { "floating": "true", + "move_to_focused_tab": "true", }, ), }, true, + true, ), SwitchToMode( Normal, |