aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins
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 /default-plugins
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 'default-plugins')
-rw-r--r--default-plugins/fixture-plugin-for-tests/src/main.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/default-plugins/fixture-plugin-for-tests/src/main.rs b/default-plugins/fixture-plugin-for-tests/src/main.rs
index 79783a1b..fcdc363f 100644
--- a/default-plugins/fixture-plugin-for-tests/src/main.rs
+++ b/default-plugins/fixture-plugin-for-tests/src/main.rs
@@ -11,6 +11,7 @@ struct State {
received_events: Vec<Event>,
received_payload: Option<String>,
configuration: BTreeMap<String, String>,
+ message_to_plugin_payload: Option<String>,
}
#[derive(Default, Serialize, Deserialize)]
@@ -34,9 +35,12 @@ impl<'de> ZellijWorker<'de> for TestWorker {
}
}
+#[cfg(target_family = "wasm")]
register_plugin!(State);
+#[cfg(target_family = "wasm")]
register_worker!(TestWorker, test_worker, TEST_WORKER);
+#[cfg(target_family = "wasm")]
impl ZellijPlugin for State {
fn load(&mut self, configuration: BTreeMap<String, String>) {
request_permission(&[
@@ -49,6 +53,8 @@ impl ZellijPlugin for State {
PermissionType::OpenTerminalsOrPlugins,
PermissionType::WriteToStdin,
PermissionType::WebAccess,
+ PermissionType::ReadCliPipes,
+ PermissionType::MessageAndLaunchOtherPlugins,
]);
self.configuration = configuration;
subscribe(&[
@@ -295,10 +301,35 @@ impl ZellijPlugin for State {
self.received_events.push(event);
should_render
}
+ fn pipe(&mut self, pipe_message: PipeMessage) -> bool {
+ let input_pipe_id = match pipe_message.source {
+ PipeSource::Cli(id) => id.clone(),
+ PipeSource::Plugin(id) => format!("{}", id),
+ };
+ let name = pipe_message.name;
+ let payload = pipe_message.payload;
+ if name == "message_name" && payload == Some("message_payload".to_owned()) {
+ unblock_cli_pipe_input(&input_pipe_id);
+ } else if name == "message_name_block" {
+ block_cli_pipe_input(&input_pipe_id);
+ } else if name == "pipe_output" {
+ cli_pipe_output(&name, "this_is_my_output");
+ } else if name == "pipe_message_to_plugin" {
+ pipe_message_to_plugin(
+ MessageToPlugin::new("message_to_plugin").with_payload("my_cool_payload"),
+ );
+ } else if name == "message_to_plugin" {
+ self.message_to_plugin_payload = payload.clone();
+ }
+ let should_render = true;
+ should_render
+ }
fn render(&mut self, rows: usize, cols: usize) {
if let Some(payload) = self.received_payload.as_ref() {
println!("Payload from worker: {:?}", payload);
+ } else if let Some(payload) = self.message_to_plugin_payload.take() {
+ println!("Payload from self: {:?}", payload);
} else {
println!(
"Rows: {:?}, Cols: {:?}, Received events: {:?}",