aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/pipe_message.rs
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/plugin_api/pipe_message.rs
parentBump rust version to 1.75.0 (#3039) (diff)
downloadsl0ppij-d780bd91052d8282ba5a7f06c6fb7faa7ca7cc18.tar.gz
sl0ppij-d780bd91052d8282ba5a7f06c6fb7faa7ca7cc18.tar.xz
sl0ppij-d780bd91052d8282ba5a7f06c6fb7faa7ca7cc18.zip
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/plugin_api/pipe_message.rs')
-rw-r--r--zellij-utils/src/plugin_api/pipe_message.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/zellij-utils/src/plugin_api/pipe_message.rs b/zellij-utils/src/plugin_api/pipe_message.rs
new file mode 100644
index 00000000..dbfe4930
--- /dev/null
+++ b/zellij-utils/src/plugin_api/pipe_message.rs
@@ -0,0 +1,71 @@
+pub use super::generated_api::api::pipe_message::{
+ Arg as ProtobufArg, PipeMessage as ProtobufPipeMessage, PipeSource as ProtobufPipeSource,
+};
+use crate::data::{PipeMessage, PipeSource};
+
+use std::convert::TryFrom;
+
+impl TryFrom<ProtobufPipeMessage> for PipeMessage {
+ type Error = &'static str;
+ fn try_from(protobuf_pipe_message: ProtobufPipeMessage) -> Result<Self, &'static str> {
+ let source = match (
+ ProtobufPipeSource::from_i32(protobuf_pipe_message.source),
+ protobuf_pipe_message.cli_source_id,
+ protobuf_pipe_message.plugin_source_id,
+ ) {
+ (Some(ProtobufPipeSource::Cli), Some(cli_source_id), _) => {
+ PipeSource::Cli(cli_source_id)
+ },
+ (Some(ProtobufPipeSource::Plugin), _, Some(plugin_source_id)) => {
+ PipeSource::Plugin(plugin_source_id)
+ },
+ _ => return Err("Invalid PipeSource or payload"),
+ };
+ let name = protobuf_pipe_message.name;
+ let payload = protobuf_pipe_message.payload;
+ let args = protobuf_pipe_message
+ .args
+ .into_iter()
+ .map(|arg| (arg.key, arg.value))
+ .collect();
+ let is_private = protobuf_pipe_message.is_private;
+ Ok(PipeMessage {
+ source,
+ name,
+ payload,
+ args,
+ is_private,
+ })
+ }
+}
+
+impl TryFrom<PipeMessage> for ProtobufPipeMessage {
+ type Error = &'static str;
+ fn try_from(pipe_message: PipeMessage) -> Result<Self, &'static str> {
+ let (source, cli_source_id, plugin_source_id) = match pipe_message.source {
+ PipeSource::Cli(input_pipe_id) => {
+ (ProtobufPipeSource::Cli as i32, Some(input_pipe_id), None)
+ },
+ PipeSource::Plugin(plugin_id) => {
+ (ProtobufPipeSource::Plugin as i32, None, Some(plugin_id))
+ },
+ };
+ let name = pipe_message.name;
+ let payload = pipe_message.payload;
+ let args: Vec<_> = pipe_message
+ .args
+ .into_iter()
+ .map(|(key, value)| ProtobufArg { key, value })
+ .collect();
+ let is_private = pipe_message.is_private;
+ Ok(ProtobufPipeMessage {
+ source,
+ cli_source_id,
+ plugin_source_id,
+ name,
+ payload,
+ args,
+ is_private,
+ })
+ }
+}