From 29f67f6fc56883402025c4c7681bfd9ceef78daa Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Thu, 24 Oct 2024 13:31:54 +0200 Subject: [PATCH] fix(layouts): suspend commands in remote layouts --- zellij-utils/src/input/actions.rs | 7 ++++++- zellij-utils/src/input/layout.rs | 32 ++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index ae83af431..b517ee2ee 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -533,6 +533,7 @@ impl Action { .or_else(|| config.and_then(|c| c.options.layout_dir)) .or_else(|| get_layout_dir(find_default_config_dir())); + let mut should_start_layout_commands_suspended = false; let (path_to_raw_layout, raw_layout, swap_layouts) = if let Some(layout_url) = layout_path.to_str().and_then(|l| { if l.starts_with("http://") || l.starts_with("https://") { @@ -541,6 +542,7 @@ impl Action { None } }) { + should_start_layout_commands_suspended = true; ( layout_url.to_owned(), Layout::stringified_from_url(layout_url) @@ -551,7 +553,7 @@ impl Action { Layout::stringified_from_path_or_default(Some(&layout_path), layout_dir) .map_err(|e| format!("Failed to load layout: {}", e))? }; - let layout = Layout::from_str(&raw_layout, path_to_raw_layout, swap_layouts.as_ref().map(|(f, p)| (f.as_str(), p.as_str())), cwd).map_err(|e| { + let mut layout = Layout::from_str(&raw_layout, path_to_raw_layout, swap_layouts.as_ref().map(|(f, p)| (f.as_str(), p.as_str())), cwd).map_err(|e| { let stringified_error = match e { ConfigError::KdlError(kdl_error) => { let error = kdl_error.add_src(layout_path.as_path().as_os_str().to_string_lossy().to_string(), String::from(raw_layout)); @@ -583,6 +585,9 @@ impl Action { }; stringified_error })?; + if should_start_layout_commands_suspended { + layout.recursively_add_start_suspended_including_template(Some(true)); + } let mut tabs = layout.tabs(); if !tabs.is_empty() { let swap_tiled_layouts = Some(layout.swap_tiled_layouts.clone()); diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index dbcd4181d..b5a40e69a 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -1167,6 +1167,7 @@ impl Layout { layout_dir: &Option, layout_info: LayoutInfo, ) -> Result { + let mut should_start_layout_commands_suspended = false; let (path_to_raw_layout, raw_layout, raw_swap_layouts) = match layout_info { LayoutInfo::File(layout_name_without_extension) => { let layout_dir = layout_dir.clone().or_else(|| default_layout_dir()); @@ -1182,17 +1183,24 @@ impl Layout { Self::stringified_from_default_assets(&PathBuf::from(layout_name))?; (Some(path_to_layout), stringified_layout, swap_layouts) }, - LayoutInfo::Url(url) => (Some(url.clone()), Self::stringified_from_url(&url)?, None), + LayoutInfo::Url(url) => { + should_start_layout_commands_suspended = true; + (Some(url.clone()), Self::stringified_from_url(&url)?, None) + }, LayoutInfo::Stringified(stringified_layout) => (None, stringified_layout, None), }; - Layout::from_kdl( + let mut layout = Layout::from_kdl( &raw_layout, path_to_raw_layout, raw_swap_layouts .as_ref() .map(|(r, f)| (r.as_str(), f.as_str())), None, - ) + ); + if should_start_layout_commands_suspended { + layout.iter_mut().next().map(|l| l.recursively_add_start_suspended_including_template(Some(true))); + } + layout } pub fn stringified_from_path_or_default( layout_path: Option<&PathBuf>, @@ -1259,7 +1267,8 @@ impl Layout { Err(e) => Err(ConfigError::DownloadError(format!("{}", e))), } })?; - let layout = Layout::from_kdl(&raw_layout, Some(url.into()), None, None)?; + let mut layout = Layout::from_kdl(&raw_layout, Some(url.into()), None, None)?; + layout.recursively_add_start_suspended_including_template(Some(true)); let config = Config::from_kdl(&raw_layout, Some(config))?; // this merges the two config, with Ok((layout, config)) } @@ -1486,7 +1495,20 @@ impl Layout { } } } - + pub fn recursively_add_start_suspended_including_template(&mut self, start_suspended: Option) { + if let Some((tiled_panes_template, floating_panes_template)) = self.template.as_mut() { + tiled_panes_template.recursively_add_start_suspended(start_suspended); + for floating_pane in floating_panes_template.iter_mut() { + floating_pane.add_start_suspended(start_suspended); + } + } + for (_tab_name, tiled_panes, floating_panes) in self.tabs.iter_mut() { + tiled_panes.recursively_add_start_suspended(start_suspended); + for floating_pane in floating_panes.iter_mut() { + floating_pane.add_start_suspended(start_suspended); + } + } + } fn swap_layout_and_path(path: &Path) -> Option<(String, String)> { // Option let mut swap_layout_path = PathBuf::from(path);