From a7c2a8b1006be362b402ace786f81ddd16a0d1ec Mon Sep 17 00:00:00 2001 From: shray sharma Date: Fri, 22 Nov 2024 20:26:15 +0100 Subject: [PATCH 1/7] upd --- src/sessions.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/sessions.rs b/src/sessions.rs index 5f77e2efef..32efe23cd4 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -19,20 +19,18 @@ use zellij_utils::{ pub(crate) fn get_sessions() -> Result, io::ErrorKind> { match fs::read_dir(&*ZELLIJ_SOCK_DIR) { Ok(files) => { - let mut sessions = Vec::new(); - files.for_each(|file| { - let file = file.unwrap(); - let file_name = file.file_name().into_string().unwrap(); - let ctime = std::fs::metadata(&file.path()) - .ok() - .and_then(|f| f.created().ok()) - .and_then(|d| d.elapsed().ok()) - .unwrap_or_default(); - let duration = Duration::from_secs(ctime.as_secs()); - if file.file_type().unwrap().is_socket() && assert_socket(&file_name) { - sessions.push((file_name, duration)); - } - }); + let sessions: Vec<_> = files + .filter_map(|file| { + let file = file.ok()?; + let file_name = file.file_name().into_string().ok()?; + let duration = file.metadata().ok()?.created().ok()?.elapsed().ok()?; + if file.file_type().ok()?.is_socket() && assert_socket(&file_name) { + Some((file_name, Duration::from_secs(duration.as_secs()))) + } else { + None + } + }) + .collect(); Ok(sessions) }, Err(err) if io::ErrorKind::NotFound != err.kind() => Err(err.kind()), From 34942d8300dcdb2ef95aceb71ac5c923518e85b3 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Fri, 22 Nov 2024 20:27:28 +0100 Subject: [PATCH 2/7] upd --- zellij-utils/src/input/layout.rs | 36 +++++++++++-------------------- zellij-utils/src/input/plugins.rs | 19 +++++++++------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index d4d8b261a5..434b24e379 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -299,33 +299,23 @@ impl Run { (None, None) => None, } } + + fn update_cwd(current: &mut Option, new: &PathBuf) { + match current { + Some(existing) => *existing = new.join(existing), + None => *current = Some(new.clone()), + } + } + pub fn add_cwd(&mut self, cwd: &PathBuf) { match self { - Run::Command(run_command) => match run_command.cwd.as_mut() { - Some(run_cwd) => { - *run_cwd = cwd.join(&run_cwd); - }, - None => { - run_command.cwd = Some(cwd.clone()); - }, - }, + Run::Command(run_command) => Self::update_cwd(&mut run_command.cwd, cwd), Run::EditFile(path_to_file, _line_number, edit_cwd) => { - match edit_cwd.as_mut() { - Some(edit_cwd) => { - *edit_cwd = cwd.join(&edit_cwd); - }, - None => { - let _ = edit_cwd.insert(cwd.clone()); - }, - }; - *path_to_file = cwd.join(&path_to_file); - }, - Run::Cwd(path) => { - *path = cwd.join(&path); - }, - Run::Plugin(run_plugin_or_alias) => { - run_plugin_or_alias.add_initial_cwd(&cwd); + Self::update_cwd(edit_cwd, cwd); + *path_to_file = cwd.join(path_to_file); }, + Run::Cwd(path) => *path = cwd.join(path), + Run::Plugin(run_plugin_or_alias) => run_plugin_or_alias.add_initial_cwd(cwd), } } pub fn add_args(&mut self, args: Option>) { diff --git a/zellij-utils/src/input/plugins.rs b/zellij-utils/src/input/plugins.rs index e1e161d3f3..6ffee394c8 100644 --- a/zellij-utils/src/input/plugins.rs +++ b/zellij-utils/src/input/plugins.rs @@ -47,6 +47,16 @@ pub struct PluginConfig { impl PluginConfig { pub fn from_run_plugin(run_plugin: &RunPlugin) -> Option { + const BUILTIN_TAGS: &[&str] = &[ + "status-bar", + "tab-bar", + "compact-bar", + "strider", + "session-manager", + "configuration", + "plugin-manager", + ]; + match &run_plugin.location { RunPluginLocation::File(path) => Some(PluginConfig { path: path.clone(), @@ -57,14 +67,7 @@ impl PluginConfig { }), RunPluginLocation::Zellij(tag) => { let tag = tag.to_string(); - if tag == "status-bar" - || tag == "tab-bar" - || tag == "compact-bar" - || tag == "strider" - || tag == "session-manager" - || tag == "configuration" - || tag == "plugin-manager" - { + if BUILTIN_TAGS.contains(&tag.as_str()) { Some(PluginConfig { path: PathBuf::from(&tag), _allow_exec_host_cmd: run_plugin._allow_exec_host_cmd, From d08ac0b1ab80f19d49c06cc948b98ef54b886892 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Sun, 24 Nov 2024 19:02:38 +0200 Subject: [PATCH 3/7] updates --- zellij-utils/src/kdl/kdl_layout_parser.rs | 99 +++++++++-------------- 1 file changed, 37 insertions(+), 62 deletions(-) diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs index 81e97a7e23..eb96c69a33 100644 --- a/zellij-utils/src/kdl/kdl_layout_parser.rs +++ b/zellij-utils/src/kdl/kdl_layout_parser.rs @@ -164,31 +164,35 @@ impl<'a> KdlLayoutParser<'a> { kdl_node: &KdlNode, ) -> Result<(), ConfigError> { if name.is_empty() { - Err(ConfigError::new_layout_kdl_error( - format!("Template names cannot be empty"), + return Err(ConfigError::new_layout_kdl_error( + "Template names cannot be empty".into(), kdl_node.span().offset(), kdl_node.span().len(), - )) - } else if name.contains(')') || name.contains('(') { - Err(ConfigError::new_layout_kdl_error( - format!("Template names cannot contain parantheses"), + )); + } + + if name.contains(')') || name.contains('(') { + return Err(ConfigError::new_layout_kdl_error( + "Template names cannot contain parentheses".into(), kdl_node.span().offset(), kdl_node.span().len(), - )) - } else if name + )); + } + + if name .chars() .next() .map(|first_char| first_char.is_numeric()) .unwrap_or(false) { - Err(ConfigError::new_layout_kdl_error( - format!("Template names cannot start with numbers"), + return Err(ConfigError::new_layout_kdl_error( + "Template names cannot start with numbers".into(), kdl_node.span().offset(), kdl_node.span().len(), - )) - } else { - Ok(()) + )); } + + Ok(()) } fn assert_no_grandchildren_in_stack( &self, @@ -1962,60 +1966,31 @@ impl<'a> KdlLayoutParser<'a> { Ok(()) } fn parse_constraint(&mut self, layout_node: &KdlNode) -> Result { - if let Some(max_panes) = kdl_get_string_property_or_child_value!(layout_node, "max_panes") { - return Err(kdl_parsing_error!( - format!( - "max_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")", - max_panes - ), - layout_node - )); - }; - if let Some(min_panes) = kdl_get_string_property_or_child_value!(layout_node, "min_panes") { - return Err(kdl_parsing_error!( - format!( - "min_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")", - min_panes - ), - layout_node - )); - }; - if let Some(exact_panes) = - kdl_get_string_property_or_child_value!(layout_node, "exact_panes") - { - return Err(kdl_parsing_error!( - format!( - "exact_panes should be a fixed number (eg. 1) and not a quoted string (\"{}\")", - exact_panes, - ), - layout_node - )); - }; - let max_panes = kdl_get_int_property_or_child_value!(layout_node, "max_panes"); - let min_panes = kdl_get_int_property_or_child_value!(layout_node, "min_panes"); - let exact_panes = kdl_get_int_property_or_child_value!(layout_node, "exact_panes"); - let mut constraint_count = 0; - let mut constraint = None; - if let Some(max_panes) = max_panes { - constraint_count += 1; - constraint = Some(LayoutConstraint::MaxPanes(max_panes as usize)); - } - if let Some(min_panes) = min_panes { - constraint_count += 1; - constraint = Some(LayoutConstraint::MinPanes(min_panes as usize)); - } - if let Some(exact_panes) = exact_panes { - constraint_count += 1; - constraint = Some(LayoutConstraint::ExactPanes(exact_panes as usize)); - } - if constraint_count > 1 { + let constraints: [(&str, fn(usize) -> LayoutConstraint); 3] = [ + ("max_panes", LayoutConstraint::MaxPanes), + ("min_panes", LayoutConstraint::MinPanes), + ("exact_panes", LayoutConstraint::ExactPanes), + ]; + + let mut applied_constraints = vec![]; + for (key, constructor) in constraints { + if let Some(value) = kdl_get_int_property_or_child_value!(layout_node, key) { + applied_constraints.push(constructor(value as usize)); + } + } + + if applied_constraints.len() > 1 { return Err(kdl_parsing_error!( - format!("cannot have more than one constraint (eg. max_panes + min_panes)'"), + String::from("Cannot define multiple constraints (e.g., max_panes + min_panes)"), layout_node )); } - Ok(constraint.unwrap_or(LayoutConstraint::NoConstraint)) + + Ok(applied_constraints + .pop() + .unwrap_or(LayoutConstraint::NoConstraint)) } + fn populate_one_swap_tiled_layout( &self, layout_node: &KdlNode, From ef7db94e0c3c744bad35aa13fcf156f4c70e90a4 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Sun, 8 Dec 2024 18:39:54 +0100 Subject: [PATCH 4/7] upd --- zellij-utils/src/plugin_api/plugin_command.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs index 4317a02e97..d31b8455ac 100644 --- a/zellij-utils/src/plugin_api/plugin_command.rs +++ b/zellij-utils/src/plugin_api/plugin_command.rs @@ -1429,7 +1429,7 @@ impl TryFrom for ProtobufPluginCommand { PluginCommand::SwitchTabTo(tab_index) => Ok(ProtobufPluginCommand { name: CommandName::SwitchTabTo as i32, payload: Some(Payload::SwitchTabToPayload(SwitchTabToPayload { - tab_index: tab_index, + tab_index, })), }), PluginCommand::SetTimeout(seconds) => Ok(ProtobufPluginCommand { @@ -1644,7 +1644,7 @@ impl TryFrom for ProtobufPluginCommand { Ok(ProtobufPluginCommand { name: CommandName::FocusTerminalPane as i32, payload: Some(Payload::FocusTerminalPanePayload(PaneIdAndShouldFloat { - pane_id: pane_id, + pane_id, should_float: should_float_if_hidden, })), }) @@ -1653,7 +1653,7 @@ impl TryFrom for ProtobufPluginCommand { Ok(ProtobufPluginCommand { name: CommandName::FocusPluginPane as i32, payload: Some(Payload::FocusPluginPanePayload(PaneIdAndShouldFloat { - pane_id: pane_id, + pane_id, should_float: should_float_if_hidden, })), }) From 9f8e53b94a693f9282a3b38c7fcd1d39f77d9906 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Sun, 8 Dec 2024 18:41:09 +0100 Subject: [PATCH 5/7] upd --- zellij-utils/src/pane_size.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-utils/src/pane_size.rs b/zellij-utils/src/pane_size.rs index fe56e720e2..3ce846e00d 100644 --- a/zellij-utils/src/pane_size.rs +++ b/zellij-utils/src/pane_size.rs @@ -164,7 +164,7 @@ impl Display for Constraint { } } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for Constraint { fn hash(&self, state: &mut H) { match self { From ce6aa2e0e6a0a2fcfbcac65339c36841f53f4dcc Mon Sep 17 00:00:00 2001 From: shray sharma Date: Sun, 8 Dec 2024 18:41:45 +0100 Subject: [PATCH 6/7] upd --- zellij-utils/src/input/actions.rs | 20 +++++++--------- zellij-utils/src/input/layout.rs | 40 +++++++++++++++++++------------ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index e19a067244..917fcf2760 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -451,18 +451,16 @@ impl Action { name, )]) } + } else if floating { + Ok(vec![Action::NewFloatingPane( + None, + name, + FloatingPaneCoordinates::new(x, y, width, height), + )]) + } else if in_place { + Ok(vec![Action::NewInPlacePane(None, name)]) } else { - if floating { - Ok(vec![Action::NewFloatingPane( - None, - name, - FloatingPaneCoordinates::new(x, y, width, height), - )]) - } else if in_place { - Ok(vec![Action::NewInPlacePane(None, name)]) - } else { - Ok(vec![Action::NewTiledPane(direction, None, name)]) - } + Ok(vec![Action::NewTiledPane(direction, None, name)]) } }, CliAction::Edit { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 434b24e379..bfc42881aa 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -299,23 +299,33 @@ impl Run { (None, None) => None, } } - - fn update_cwd(current: &mut Option, new: &PathBuf) { - match current { - Some(existing) => *existing = new.join(existing), - None => *current = Some(new.clone()), - } - } - pub fn add_cwd(&mut self, cwd: &PathBuf) { match self { - Run::Command(run_command) => Self::update_cwd(&mut run_command.cwd, cwd), + Run::Command(run_command) => match run_command.cwd.as_mut() { + Some(run_cwd) => { + *run_cwd = cwd.join(&run_cwd); + }, + None => { + run_command.cwd = Some(cwd.clone()); + }, + }, Run::EditFile(path_to_file, _line_number, edit_cwd) => { - Self::update_cwd(edit_cwd, cwd); - *path_to_file = cwd.join(path_to_file); + match edit_cwd.as_mut() { + Some(edit_cwd) => { + *edit_cwd = cwd.join(&edit_cwd); + }, + None => { + let _ = edit_cwd.insert(cwd.clone()); + }, + }; + *path_to_file = cwd.join(&path_to_file); + }, + Run::Cwd(path) => { + *path = cwd.join(&path); + }, + Run::Plugin(run_plugin_or_alias) => { + run_plugin_or_alias.add_initial_cwd(&cwd); }, - Run::Cwd(path) => *path = cwd.join(path), - Run::Plugin(run_plugin_or_alias) => run_plugin_or_alias.add_initial_cwd(cwd), } } pub fn add_args(&mut self, args: Option>) { @@ -389,7 +399,7 @@ impl Run { } } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Debug, Serialize, Deserialize, Clone, Hash, Default)] pub struct RunPlugin { #[serde(default)] @@ -475,7 +485,7 @@ impl PluginAlias { } } -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl PartialEq for RunPlugin { fn eq(&self, other: &Self) -> bool { // TODO: normalize paths here if the location is a file so that relative/absolute paths From ea61b7628565e1e87420489569a71eba82ac24c5 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Sun, 8 Dec 2024 18:43:55 +0100 Subject: [PATCH 7/7] upd --- zellij-utils/src/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 1d0da685e3..8da97e59c4 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -1241,7 +1241,7 @@ impl LayoutInfo { use std::hash::{Hash, Hasher}; -#[allow(clippy::derive_hash_xor_eq)] +#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for SessionInfo { fn hash(&self, state: &mut H) { self.name.hash(state);