summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-01-17 12:10:49 +0100
committerGitHub <noreply@github.com>2024-01-17 12:10:49 +0100
commitd780bd91052d8282ba5a7f06c6fb7faa7ca7cc18 (patch)
treeca08219a38b9e6a3b1c027682359074c86e0dbb5 /zellij-utils/src/input
parentf6d57295a02393e26c74afb007bf673bcbb454e8 (diff)
feat(plugins): introduce 'pipes', allowing users to pipe data to and control plugins from the command line (#3066)
* prototype - working with message from the cli * prototype - pipe from the CLI to plugins * prototype - pipe from the CLI to plugins and back again * prototype - working with better cli interface * prototype - working after removing unused stuff * prototype - working with launching plugin if it is not launched, also fixed event ordering * refactor: change message to cli-message * prototype - allow plugins to send messages to each other * fix: allow cli messages to send plugin parameters (and implement backpressure) * fix: use input_pipe_id to identify cli pipes instead of their message name * fix: come cleanups and add skip_cache parameter * fix: pipe/client-server communication robustness * fix: leaking messages between plugins while loading * feat: allow plugins to specify how a new plugin instance is launched when sending messages * fix: add permissions * refactor: adjust cli api * fix: improve cli plugin loading error messages * docs: cli pipe * fix: take plugin configuration into account when messaging between plugins * refactor: pipe message protobuf interface * refactor: update(event) -> pipe * refactor - rename CliMessage to CliPipe * fix: add is_private to pipes and change some naming * refactor - cli client * refactor: various cleanups * style(fmt): rustfmt * fix(pipes): backpressure across multiple plugins * style: some cleanups * style(fmt): rustfmt * style: fix merge conflict mistake * style(wording): clarify pipe permission
Diffstat (limited to 'zellij-utils/src/input')
-rw-r--r--zellij-utils/src/input/actions.rs51
-rw-r--r--zellij-utils/src/input/layout.rs3
2 files changed, 54 insertions, 0 deletions
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index 8af5d28ee..74c6c1e2e 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -13,6 +13,8 @@ use crate::input::config::{Config, ConfigError, KdlError};
use crate::input::options::OnForceClose;
use miette::{NamedSource, Report};
use serde::{Deserialize, Serialize};
+use std::collections::BTreeMap;
+use uuid::Uuid;
use std::path::PathBuf;
use std::str::FromStr;
@@ -256,6 +258,20 @@ pub enum Action {
BreakPaneRight,
BreakPaneLeft,
RenameSession(String),
+ CliPipe {
+ pipe_id: String,
+ name: Option<String>,
+ payload: Option<String>,
+ args: Option<BTreeMap<String, String>>,
+ plugin: Option<String>,
+ configuration: Option<BTreeMap<String, String>>,
+ launch_new: bool,
+ skip_cache: bool,
+ floating: Option<bool>,
+ in_place: Option<bool>,
+ cwd: Option<PathBuf>,
+ pane_title: Option<String>,
+ },
}
impl Action {
@@ -582,6 +598,41 @@ impl Action {
)])
},
CliAction::RenameSession { name } => Ok(vec![Action::RenameSession(name)]),
+ CliAction::Pipe {
+ name,
+ payload,
+ args,
+ plugin,
+ plugin_configuration,
+ force_launch_plugin,
+ skip_plugin_cache,
+ floating_plugin,
+ in_place_plugin,
+ plugin_cwd,
+ plugin_title,
+ } => {
+ let current_dir = get_current_dir();
+ let cwd = plugin_cwd
+ .map(|cwd| current_dir.join(cwd))
+ .or_else(|| Some(current_dir));
+ let skip_cache = skip_plugin_cache;
+ let pipe_id = Uuid::new_v4().to_string();
+ Ok(vec![Action::CliPipe {
+ pipe_id,
+ name,
+ payload,
+ args: args.map(|a| a.inner().clone()), // TODO: no clone somehow
+ plugin,
+ configuration: plugin_configuration.map(|a| a.inner().clone()), // TODO: no clone
+ // somehow
+ launch_new: force_launch_plugin,
+ floating: floating_plugin,
+ in_place: in_place_plugin,
+ cwd,
+ pane_title: plugin_title,
+ skip_cache,
+ }])
+ },
}
}
}
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index 40ca72097..82dab15ee 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -265,6 +265,9 @@ impl PluginUserConfiguration {
pub fn inner(&self) -> &BTreeMap<String, String> {
&self.0
}
+ pub fn insert(&mut self, config_key: impl Into<String>, config_value: impl Into<String>) {
+ self.0.insert(config_key.into(), config_value.into());
+ }
}
impl FromStr for PluginUserConfiguration {