diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-16 17:07:27 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2024-02-16 17:07:27 +0100 |
commit | 7699efead491a8b52f62d12a021e9ee47f85a5dc (patch) | |
tree | e61f557e95d1cb87a8c9396f4f84aff34bc3012c | |
parent | b677ffe75fb8e518441a0bd7df02abfb8dcc4989 (diff) |
working prototype with passing tests
43 files changed, 1364 insertions, 991 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs index ad1a03fd1..c8c8b42b6 100644 --- a/zellij-server/src/panes/floating_panes/mod.rs +++ b/zellij-server/src/panes/floating_panes/mod.rs @@ -25,7 +25,7 @@ use zellij_utils::{ data::{ModeInfo, Style}, errors::prelude::*, input::command::RunCommand, - input::layout::{FloatingPaneLayout, Run, RunPlugin}, + input::layout::{FloatingPaneLayout, Run, RunPlugin, RunPluginOrAlias}, pane_size::{Dimension, Offset, PaneGeom, Size, SizeInPixels, Viewport}, }; @@ -872,12 +872,28 @@ impl FloatingPanes { self.focus_pane_for_all_clients(active_pane_id); } } - pub fn get_plugin_pane_id(&self, run_plugin: &RunPlugin) -> Option<PaneId> { - let run = Some(Run::Plugin(run_plugin.clone())); - self.panes - .iter() - .find(|(_id, s_p)| s_p.invoked_with() == &run) - .map(|(id, _)| *id) + pub fn get_plugin_pane_id(&self, run_plugin_or_alias: &RunPluginOrAlias) -> Option<PaneId> { + match run_plugin_or_alias { + RunPluginOrAlias::RunPlugin(..) => { + let run = Some(Run::Plugin(run_plugin_or_alias.clone())); + self.panes + .iter() + .find(|(_id, s_p)| s_p.invoked_with() == &run) + .map(|(id, _)| *id) + } + RunPluginOrAlias::Alias(plugin_alias) => { + self.panes + .iter() + .find(|(_id, s_p)| { + match s_p.invoked_with() { + // Some(Run::Plugin(RunPluginOrAlias::Alias(pane_alias))) => pane_alias.name == plugin_alias.name, + Some(Run::Plugin(RunPluginOrAlias::Alias(pane_alias))) => pane_alias.name == plugin_alias.name && pane_alias.configuration == plugin_alias.configuration, + _ => false + } + }) + .map(|(id, _)| *id) + } + } } pub fn focus_pane_if_exists(&mut self, pane_id: PaneId, client_id: ClientId) -> Result<()> { if self.panes.get(&pane_id).is_some() { diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs index 6477a8af0..57444c4e9 100644 --- a/zellij-server/src/panes/tiled_panes/mod.rs +++ b/zellij-server/src/panes/tiled_panes/mod.rs @@ -22,7 +22,7 @@ use zellij_utils::{ errors::prelude::*, input::{ command::RunCommand, - layout::{Run, RunPlugin, SplitDirection}, + layout::{Run, RunPlugin, RunPluginOrAlias, SplitDirection}, }, pane_size::{Offset, PaneGeom, Size, SizeInPixels, Viewport}, }; @@ -1744,12 +1744,27 @@ impl TiledPanes { fn reset_boundaries(&mut self) { self.client_id_to_boundaries.clear(); } - pub fn get_plugin_pane_id(&self, run_plugin: &RunPlugin) -> Option<PaneId> { - let run = Some(Run::Plugin(run_plugin.clone())); - self.panes - .iter() - .find(|(_id, s_p)| s_p.invoked_with() == &run) - .map(|(id, _)| *id) + pub fn get_plugin_pane_id(&self, run_plugin_or_alias: &RunPluginOrAlias) -> Option<PaneId> { + match run_plugin_or_alias { + RunPluginOrAlias::RunPlugin(..) => { + let run = Some(Run::Plugin(run_plugin_or_alias.clone())); + self.panes + .iter() + .find(|(_id, s_p)| s_p.invoked_with() == &run) + .map(|(id, _)| *id) + } + RunPluginOrAlias::Alias(plugin_alias) => { + self.panes + .iter() + .find(|(_id, s_p)| { + match s_p.invoked_with() { + Some(Run::Plugin(RunPluginOrAlias::Alias(pane_alias))) => pane_alias.name == plugin_alias.name && pane_alias.configuration == plugin_alias.configuration, + _ => false + } + }) + .map(|(id, _)| *id) + } + } } pub fn pane_info(&self) -> Vec<PaneInfo> { let mut pane_infos = vec![]; diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index ebae02a39..e816d1578 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -33,7 +33,7 @@ use zellij_utils::{ input::{ command::TerminalAction, layout::{ - FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation, + FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginOrAlias, TiledPaneLayout, }, plugins::PluginsConfig, @@ -50,7 +50,7 @@ pub enum PluginInstruction { Option<bool>, // should float bool, // should be opened in place Option<String>, // pane title - RunPlugin, + RunPluginOrAlias, usize, // tab index Option<PaneId>, // pane id to replace if this is to be opened "in-place" ClientId, @@ -63,7 +63,7 @@ pub enum PluginInstruction { Reload( Option<bool>, // should float Option<String>, // pane title - RunPlugin, + RunPluginOrAlias, usize, // tab index Size, ), @@ -174,7 +174,7 @@ pub(crate) fn plugin_thread_main( store: Store, data_dir: PathBuf, plugins: PluginsConfig, - layout: Box<Layout>, + mut layout: Box<Layout>, path_to_default_shell: PathBuf, zellij_cwd: PathBuf, capabilities: PluginCapabilities, @@ -186,6 +186,18 @@ pub(crate) fn plugin_thread_main( let plugin_dir = data_dir.join("plugins/"); let plugin_global_data_dir = plugin_dir.join("data"); + // TODO: better, not hard coded here, etc. + let mut plugin_aliases = HashMap::new(); + let mut filter_configuration = BTreeMap::new(); + filter_configuration.insert("key_from_dict".to_owned(), "value_from_dict".to_owned()); + plugin_aliases.insert("session-manager-alias", RunPlugin::from_url("zellij:session-manager").unwrap()); + plugin_aliases.insert("filepicker", RunPlugin::from_url("zellij:strider").unwrap()); + plugin_aliases.insert( + "filter", + RunPlugin::from_url("file:/home/aram/code/rust-plugin-example/target/wasm32-wasi/debug/rust-plugin-example.wasm").unwrap().with_configuration(filter_configuration) + ); + layout.populate_plugin_aliases_in_layout(&plugin_aliases); + let store = Arc::new(Mutex::new(store)); // use this channel to ensure that tasks spawned from this thread terminate before exiting @@ -213,90 +225,103 @@ pub(crate) fn plugin_thread_main( should_float, should_be_open_in_place, pane_title, - run, + mut run_plugin_or_alias, tab_index, pane_id_to_replace, client_id, size, cwd, skip_cache, - ) => match wasm_bridge.load_plugin( - &run, - Some(tab_index), - size, - cwd.clone(), - skip_cache, - Some(client_id), - None, - ) { - Ok((plugin_id, client_id)) => { - drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( - should_float, - should_be_open_in_place, - run, - pane_title, - Some(tab_index), - plugin_id, - pane_id_to_replace, - cwd, - Some(client_id), - ))); - }, - Err(e) => { - log::error!("Failed to load plugin: {e}"); - }, - }, + ) => { + log::info!("run_plugin_or_alias: {:?}", run_plugin_or_alias); + run_plugin_or_alias.populate_run_plugin_if_needed(&plugin_aliases); + let run_plugin = run_plugin_or_alias.get_run_plugin(); + match wasm_bridge.load_plugin( + &run_plugin, + Some(tab_index), + size, + cwd.clone(), + skip_cache, + Some(client_id), + None, + ) { + Ok((plugin_id, client_id)) => { + drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( + should_float, + should_be_open_in_place, + run_plugin_or_alias, + pane_title, + Some(tab_index), + plugin_id, + pane_id_to_replace, + cwd, + Some(client_id), + ))); + }, + Err(e) => { + log::error!("Failed to load plugin: {e}"); + }, + } + } PluginInstruction::Update(updates) => { wasm_bridge.update_plugins(updates, shutdown_send.clone())?; }, PluginInstruction::Unload(pid) => { wasm_bridge.unload_plugin(pid)?; }, - PluginInstruction::Reload(should_float, pane_title, run, tab_index, size) => { - match wasm_bridge.reload_plugin(&run) { - Ok(_) => { - let _ = bus - .senders - .send_to_server(ServerInstruction::UnblockInputThread); - }, - Err(err) => match err.downcast_ref::<ZellijError>() { - Some(ZellijError::PluginDoesNotExist) => { - log::warn!("Plugin {} not found, starting it instead", run.location); - // we intentionally do not provide the client_id here because it belongs to - // the cli who spawned the command and is not an existing client_id - let skip_cache = true; // when reloading we always skip cache - match wasm_bridge.load_plugin( - &run, - Some(tab_index), - size, - None, - skip_cache, - None, - None, - ) { - Ok((plugin_id, _client_id)) => { - let should_be_open_in_place = false; - drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( - should_float, - should_be_open_in_place, - run, - pane_title, + PluginInstruction::Reload(should_float, pane_title, mut run_plugin_or_alias, tab_index, size) => { + run_plugin_or_alias.populate_run_plugin_if_needed(&plugin_aliases); + match run_plugin_or_alias.get_run_plugin() { + Some(run_plugin) => { + match wasm_bridge.reload_plugin(&run_plugin) { + Ok(_) => { + let _ = bus + .senders + .send_to_server(ServerInstruction::UnblockInputThread); + }, + Err(err) => match err.downcast_ref::<ZellijError>() { + Some(ZellijError::PluginDoesNotExist) => { + log::warn!("Plugin {} not found, starting it instead", run_plugin.location); + // we intentionally do not provide the client_id here because it belongs to + // the cli who spawned the command and is not an existing client_id + let skip_cache = true; // when reloading we always skip cache + match wasm_bridge.load_plugin( + &Some(run_plugin), Some(tab_index), - plugin_id, + size, None, + skip_cache, None, None, - ))); + ) { + Ok((plugin_id, _client_id)) => { + let should_be_open_in_place = false; + drop(bus.senders.send_to_screen(ScreenInstruction::AddPlugin( + should_float, + should_be_open_in_place, + run_plugin_or_alias, + pane_title, + Some(tab_index), + plugin_id, + None, + None, + None, + ))); + }, + Err(e) => { + log::error!("Failed to load plugin: {e}"); + }, + }; }, - Err(e) => { - log::error!("Failed to load plugin: {e}"); + _ => { + return Err(err); }, - }; - }, - _ => { - return Err(err); - }, + }, |