summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-02-26 10:47:48 +0100
committerAram Drevekenin <aram@poor.dev>2024-02-26 10:47:48 +0100
commitaf17598f3d121fe0373d7f766b17cd437ce0ab49 (patch)
tree9424c879b3ab083b3861f5b266cb6b4578dcaeba
parent178b0c0e1af11a326d5631fddd1f0515be682224 (diff)
style(fmt): rustfmt
-rw-r--r--zellij-server/src/panes/floating_panes/mod.rs3
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs4
-rw-r--r--zellij-server/src/plugins/mod.rs71
-rw-r--r--zellij-server/src/plugins/unit/plugin_tests.rs23
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs18
-rw-r--r--zellij-server/src/plugins/zellij_exports.rs2
-rw-r--r--zellij-server/src/pty.rs6
-rw-r--r--zellij-server/src/screen.rs68
-rw-r--r--zellij-server/src/session_layout_metadata.rs3
-rw-r--r--zellij-server/src/tab/layout_applier.rs4
-rw-r--r--zellij-server/src/tab/mod.rs15
-rw-r--r--zellij-server/src/tab/unit/tab_integration_tests.rs4
-rw-r--r--zellij-server/src/unit/screen_tests.rs4
-rw-r--r--zellij-utils/src/input/actions.rs30
-rw-r--r--zellij-utils/src/input/config.rs10
-rw-r--r--zellij-utils/src/input/layout.rs112
-rw-r--r--zellij-utils/src/input/plugins.rs20
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs12
-rw-r--r--zellij-utils/src/kdl/mod.rs28
-rw-r--r--zellij-utils/src/plugin_api/action.rs47
-rw-r--r--zellij-utils/src/session_serialization.rs16
21 files changed, 306 insertions, 194 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs
index 37e660253..07ed6173d 100644
--- a/zellij-server/src/panes/floating_panes/mod.rs
+++ b/zellij-server/src/panes/floating_panes/mod.rs
@@ -873,7 +873,8 @@ impl FloatingPanes {
}
}
pub fn get_plugin_pane_id(&self, run_plugin_or_alias: &RunPluginOrAlias) -> Option<PaneId> {
- self.panes.iter()
+ self.panes
+ .iter()
.find(|(_id, pane)| run_plugin_or_alias.is_equivalent_to_run(pane.invoked_with()))
.map(|(id, _)| *id)
}
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index 7292644e3..8e594b27f 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -1745,10 +1745,10 @@ impl TiledPanes {
self.client_id_to_boundaries.clear();
}
pub fn get_plugin_pane_id(&self, run_plugin_or_alias: &RunPluginOrAlias) -> Option<PaneId> {
- self.panes.iter()
+ self.panes
+ .iter()
.find(|(_id, pane)| run_plugin_or_alias.is_equivalent_to_run(pane.invoked_with()))
.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 adf13ce4f..80a590453 100644
--- a/zellij-server/src/plugins/mod.rs
+++ b/zellij-server/src/plugins/mod.rs
@@ -32,10 +32,7 @@ use zellij_utils::{
errors::{prelude::*, ContextType, PluginContext},
input::{
command::TerminalAction,
- layout::{
- FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginOrAlias,
- TiledPaneLayout
- },
+ layout::{FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginOrAlias, TiledPaneLayout},
plugins::PluginAliases,
},
ipc::ClientAttributes,
@@ -247,14 +244,20 @@ pub(crate) fn plugin_thread_main(
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, mut run_plugin_or_alias, tab_index, size) => {
+ 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) => {
@@ -266,7 +269,10 @@ pub(crate) fn plugin_thread_main(
},
Err(err) => match err.downcast_ref::<ZellijError>() {
Some(ZellijError::PluginDoesNotExist) => {
- log::warn!("Plugin {} not found, starting it instead", run_plugin.location);
+ 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
@@ -281,17 +287,19 @@ pub(crate) fn plugin_thread_main(
) {
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,
- )));
+ 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}");
@@ -306,7 +314,7 @@ pub(crate) fn plugin_thread_main(
},
None => {
log::error!("Failed to find plugin info for: {:?}", run_plugin_or_alias)
- }
+ },
}
},
PluginInstruction::Resize(pid, new_columns, new_rows) => {
@@ -326,16 +334,16 @@ pub(crate) fn plugin_thread_main(
tab_index,
client_id,
) => {
- let mut plugin_ids: HashMap<
- RunPluginOrAlias,
- Vec<PluginId>,
- > = HashMap::new();
+ let mut plugin_ids: HashMap<RunPluginOrAlias, Vec<PluginId>> = HashMap::new();
tab_layout = tab_layout.or_else(|| Some(layout.new_tab().0));
- tab_layout.as_mut().map(|t| t.populate_plugin_aliases_in_layout(&plugin_aliases));
- floating_panes_layout
- .iter_mut().for_each(|f| {
- f.run.as_mut().map(|f| f.populate_run_plugin_if_needed(&plugin_aliases));
- });
+ tab_layout
+ .as_mut()
+ .map(|t| t.populate_plugin_aliases_in_layout(&plugin_aliases));
+ floating_panes_layout.iter_mut().for_each(|f| {
+ f.run
+ .as_mut()
+ .map(|f| f.populate_run_plugin_if_needed(&plugin_aliases));
+ });
let mut extracted_run_instructions = tab_layout
.clone()
.unwrap_or_else(|| layout.new_tab().0)
@@ -683,7 +691,12 @@ fn pipe_to_specific_plugins(
) {
let is_private = true;
let size = Size::default();
- match RunPluginOrAlias::from_url(&plugin_url, configuration, Some(plugin_aliases), cwd.clone()) {
+ match RunPluginOrAlias::from_url(
+ &plugin_url,
+ configuration,
+ Some(plugin_aliases),
+ cwd.clone(),
+ ) {
Ok(run_plugin_or_alias) => {
let all_plugin_ids = wasm_bridge.get_or_load_plugins(
run_plugin_or_alias,
diff --git a/zellij-server/src/plugins/unit/plugin_tests.rs b/zellij-server/src/plugins/unit/plugin_tests.rs
index 3c19a5bc6..07212c3b3 100644
--- a/zellij-server/src/plugins/unit/plugin_tests.rs
+++ b/zellij-server/src/plugins/unit/plugin_tests.rs
@@ -8,7 +8,9 @@ use tempfile::tempdir;
use wasmer::Store;
use zellij_utils::data::{Event, Key, PermissionStatus, PermissionType, PluginCapabilities};
use zellij_utils::errors::ErrorContext;
-use zellij_utils::input::layout::{Layout, PluginUserConfiguration, RunPlugin, RunPluginOrAlias, RunPluginLocation, PluginAlias};
+use zellij_utils::input::layout::{
+ Layout, PluginAlias, PluginUserConfiguration, RunPlugin, RunPluginLocation, RunPluginOrAlias,
+};
use zellij_utils::input::permission::PermissionCache;
use zellij_utils::input::plugins::PluginAliases;
use zellij_utils::ipc::ClientAttributes;
@@ -250,12 +252,16 @@ fn create_plugin_thread(
let client_attributes = ClientAttributes::default();
let default_shell_action = None; // TODO: change me
let mut plugin_aliases = PluginAliases::default();
- plugin_aliases.aliases.insert("fixture_plugin_for_tests".to_owned(),
- RunPlugin::from_url(
- &format!(
- "file:{}/../target/e2e-data/plugins/fixture-plugin-for-tests.wasm",
- std::env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy())).unwrap()
- );
+ plugin_aliases.aliases.insert(
+ "fixture_plugin_for_tests".to_owned(),
+ RunPlugin::from_url(&format!(
+ "file:{}/../target/e2e-data/plugins/fixture-plugin-for-tests.wasm",
+ std::env::var_os("CARGO_MANIFEST_DIR")
+ .unwrap()
+ .to_string_lossy()
+ ))
+ .unwrap(),
+ );
let plugin_thread = std::thread::Builder::new()
.name("plugin_thread".to_string())
.spawn(move || {
@@ -5499,7 +5505,8 @@ pub fn denied_permission_request_result() {
teardown();
let permission_cache = PermissionCache::from_path_or_default(Some(cache_path));
- let permissions = permission_cache.get_permissions(PathBuf::from(&*PLUGIN_FIXTURE).display().to_string());
+ let permissions =
+ permission_cache.get_permissions(PathBuf::from(&*PLUGIN_FIXTURE).display().to_string());
assert_snapshot!(format!("{:#?}", permissions));
}
diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs
index 84e1740c1..10a1f51a2 100644
--- a/zellij-server/src/plugins/wasm_bridge.rs
+++ b/zellij-server/src/plugins/wasm_bridge.rs
@@ -37,7 +37,7 @@ use zellij_utils::{
errors::prelude::*,
input::{
command::TerminalAction,
- layout::{Layout, PluginUserConfiguration, RunPlugin, RunPluginOrAlias, RunPluginLocation},
+ layout::{Layout, PluginUserConfiguration, RunPlugin, RunPluginLocation, RunPluginOrAlias},
plugins::PluginConfig,
},
ipc::ClientAttributes,
@@ -199,8 +199,9 @@ impl WasmBridge {
let default_shell = self.default_shell.clone();
let default_layout = self.default_layout.clone();
async move {
- let _ =
- senders.send_to_background_jobs(BackgroundJob::AnimatePluginLoading(plugin_id));
+ let _ = senders.send_to_background_jobs(
+ BackgroundJob::AnimatePluginLoading(plugin_id),
+ );
let mut loading_indication = LoadingIndication::new(plugin_name.clone());
if let RunPluginLocation::Remote(url) = &plugin.location {
@@ -273,7 +274,7 @@ impl WasmBridge {
"Failed to resolve plugin alias",
None,
);
- }
+ },
}
Ok((plugin_id, client_id))
}
@@ -1104,9 +1105,10 @@ impl WasmBridge {
&run_plugin.configuration,
);
if all_plugin_ids.is_empty() {
- if let Some(loading_plugin_id) =
- self.plugin_id_of_loading_plugin(&run_plugin.location, &run_plugin.configuration)
- {
+ if let Some(loading_plugin_id) = self.plugin_id_of_loading_plugin(
+ &run_plugin.location,
+ &run_plugin.configuration,
+ ) {
return vec![(loading_plugin_id, None)];
}
match self.load_plugin(
@@ -1150,7 +1152,7 @@ impl WasmBridge {
None => {
log::error!("Plugin not found for alias");
vec![]
- }
+ },
}
}
pub fn clear_plugin_map_cache(&mut self) {
diff --git a/zellij-server/src/plugins/zellij_exports.rs b/zellij-server/src/plugins/zellij_exports.rs
index c0c5e5999..533d85f2f 100644
--- a/zellij-server/src/plugins/zellij_exports.rs
+++ b/zellij-server/src/plugins/zellij_exports.rs
@@ -1225,7 +1225,7 @@ fn start_or_reload_plugin(env: &ForeignFunctionEnv, url: &str) -> Result<()> {
};
let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
let run_plugin_or_alias = RunPluginOrAlias::from_url(url, &None, None, Some(cwd))
- .map_err(|e| anyhow!("Failed to parse plugin location: {}", e))?;
+ .map_err(|e| anyhow!("Failed to parse plugin location: {}", e))?;
let action = Action::StartOrReloadPlugin(run_plugin_or_alias);
apply_action!(action, error_msg, env);
Ok(())
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs
index f4fbf2ebf..209970530 100644
--- a/zellij-server/src/pty.rs
+++ b/zellij-server/src/pty.rs
@@ -19,8 +19,8 @@ use zellij_utils::{
input::{
command::{RunCommand, TerminalAction},
layout::{
- FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPluginOrAlias, RunPluginLocation,
- TiledPaneLayout,
+ FloatingPaneLayout, Layout, PluginUserConfiguration, Run, RunPluginLocation,
+ RunPluginOrAlias, TiledPaneLayout,
},
},
pane_size::Size,
@@ -62,7 +62,7 @@ pub enum PtyInstruction {
Option<TerminalAction>,
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
- usize, // tab_index
+ usize, // tab_index
HashMap<RunPluginOrAlias, Vec<u32>>, // plugin_ids
ClientId,
), // the String is the tab name
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 5faba40c4..2e351cff4 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -19,7 +19,7 @@ use zellij_utils::{
envs::set_session_name,
input::command::TerminalAction,
input::layout::{
- FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginOrAlias, RunPluginLocation,
+ FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginLocation, RunPluginOrAlias,
SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
},
position::Position,
@@ -276,7 +276,13 @@ pub enum ScreenInstruction {
PreviousSwapLayout(ClientId),
NextSwapLayout(ClientId),
QueryTabNames(ClientId),
- NewTiledPluginPane(RunPluginOrAlias, Option<String>, bool, Option<PathBuf>, ClientId), // Option<String> is
+ NewTiledPluginPane(
+ RunPluginOrAlias,
+ Option<String>,
+ bool,
+ Option<PathBuf>,
+ ClientId,
+ ), // Option<String> is
// optional pane title, bool is skip cache, Option<PathBuf> is an optional cwd
NewFloatingPluginPane(
RunPluginOrAlias,
@@ -306,7 +312,15 @@ pub enum ScreenInstruction {
StartPluginLoadingIndication(u32, LoadingIndication), // u32 - plugin_id
ProgressPluginLoadingOffset(u32), // u32 - plugin id
RequestStateUpdateForPlugins,
- LaunchOrFocusPlugin(RunPluginOrAlias, bool, bool, bool, Option<PaneId>, bool, ClientId), // bools are: should_float, move_to_focused_tab, should_open_in_place, Option<PaneId> is the pane id to replace, bool following it is skip_cache
+ LaunchOrFocusPlugin(
+ RunPluginOrAlias,
+ bool,
+ bool,
+ bool,
+ Option<PaneId>,
+ bool,
+ ClientId,
+ ), // bools are: should_float, move_to_focused_tab, should_open_in_place, Option<PaneId> is the pane id to replace, bool following it is skip_cache
LaunchPlugin(
RunPluginOrAlias,
bool,
@@ -3471,31 +3485,33 @@ pub(crate) fn screen_thread_main(
skip_cache,
client_id,
) => match pane_id_to_replace {
- Some(pane_id_to_replace) if should_open_in_place => match screen.active_tab_indices.values().next() {
- Some(tab_index) => {
- let size = Size::default();
- screen
- .bus
- .senders
- .send_to_pty(PtyInstruction::FillPluginCwd(
- Some(should_float),
- should_open_in_place,
- None,
- run_plugin,
- *tab_index,
- Some(pane_id_to_replace),
- client_id,
- size,
- skip_cache,
- None,
- None,
- ))?;
- },
- None => {
- log::error!(
+ Some(pane_id_to_replace) if should_open_in_place => {
+ match screen.active_tab_indices.values().next() {
+ Some(tab_index) => {
+ let size = Size::default();
+ screen
+ .bus
+ .senders
+ .send_to_pty(PtyInstruction::FillPluginCwd(
+ Some(should_float),
+ should_open_in_place,
+ None,
+ run_plugin,
+ *tab_index,
+ Some(pane_id_to_replace),
+ client_id,
+ size,
+ skip_cache,
+ None,
+ None,
+ ))?;
+ },
+ None => {
+ log::error!(
"Could not find an active tab - is there at least 1 connected user?"
);
- },
+ },
+ }
},
_ => {
let client_id = if screen.active_tab_indices.contains_key(&client_id) {
diff --git a/zellij-server/src/session_layout_metadata.rs b/zellij-server/src/session_layout_metadata.rs
index f760bdb4d..da19bc908 100644
--- a/zellij-server/src/session_layout_metadata.rs
+++ b/zellij-server/src/session_layout_metadata.rs
@@ -178,7 +178,8 @@ impl SessionLayoutMetadata {
let mut update_cmd_in_pane_metadata = |pane_layout_metadata: &mut PaneLayoutMetadata| {
if let PaneId::Plugin(id) = pane_layout_metadata.id {
if let Some(run_plugin) = plugin_ids_to_run_plugins.remove(&id) {
- pane_layout_metadata.run = Some(Run::Plugin(RunPluginOrAlias::RunPlugin(run_plugin)));
+ pane_layout_metadata.run =
+ Some(Run::Plugin(RunPluginOrAlias::RunPlugin(run_plugin)));
}
}
};
diff --git a/zellij-server/src/tab/layout_applier.rs b/zellij-server/src/tab/layout_applier.rs
index bd0468a60..c66fac170 100644
--- a/zellij-server/src/tab/layout_applier.rs
+++ b/zellij-server/src/tab/layout_applier.rs
@@ -18,9 +18,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::rc::Rc;
use zellij_utils::{
data::{Palette, Style},
- input::layout::{
- FloatingPaneLayout, Run, RunPluginOrAlias, TiledPaneLayout,
- },
+ input::layout::{FloatingPaneLayout, Run, RunPluginOrAlias, TiledPaneLayout},
pane_size::{Offset, PaneGeom, Size, SizeInPixels, Viewport},
};
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index de0ee7240..8c135b7d0 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -50,8 +50,8 @@ use zellij_utils::{
input::{
command::TerminalAction,
layout::{
- FloatingPaneLayout, PluginUserConfiguration, Run, RunPlugin, RunPluginOrAlias, RunPluginLocation,
- SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
+ FloatingPaneLayout, PluginUserConfiguration, Run, RunPlugin, RunPluginLocation,
+ RunPluginOrAlias, SwapFloatingLayout, SwapTiledLayout, TiledPaneLayout,
},
parse_keys,
},
@@ -3592,8 +3592,11 @@ impl Tab {
.get_plugin_pane_id(run_plugin_or_alias)
.or_else(|| self.floating_panes.get_plugin_pane_id(run_plugin_or_alias))
.or_else(|| {
- self.suppressed_panes.iter()
- .find(|(_id, (_, pane))| run_plugin_or_alias.is_equivalent_to_run(pane.invoked_with()))
+ self.suppressed_panes
+ .iter()
+ .find(|(_id, (_, pane))| {
+ run_plugin_or_alias.is_equivalent_to_run(pane.invoked_with())
+ })
.map(|(id, _)| *id)
})
}
@@ -3767,9 +3770,7 @@ pub fn pane_info_for_pane(pane_id: &PaneId, pane: &Box<dyn Pane>) -> PaneInfo {
pane_info.id = *plugin_id;
pane_info.is_plugin = true;
pane_info.plugin_url = pane.invoked_with().as_ref().and_then(|c| match c {
- Run::Plugin(run_plugin_or_alias) => {
- Some(run_plugin_or_alias.location_string())
- }
+ Run::Plugin(run_plugin_or_alias) => Some(run_plugin_or_alias.location_string()),
_ => None,
});
},
diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs
index b33a0cfe3..f8953235e 100644
--- a/zellij-server/src/tab/unit/tab_integration_tests.rs
+++ b/zellij-server/src/tab/unit/tab_integration_tests.rs
@@ -20,8 +20,8 @@ use zellij_utils::data::ResizeStrategy;
use zellij_utils::envs::set_session_name;
use zellij_utils::errors::{prelude::*, ErrorContext};
use zellij_utils::input::layout::{
- FloatingPaneLayout, Layout, PluginUserConfiguration, RunPluginOrAlias, RunPluginLocation, SwapFloatingLayout,
- SwapTiledLayout, TiledPaneLayout,
+ Floati