aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input/layout.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2025-08-28 17:48:34 +0200
committerGitHub <noreply@github.com>2025-08-28 17:48:34 +0200
commit3a26df6314cf5966ffb3065b97d4183b480d1441 (patch)
tree0afc4bc62272f22c397ccab260a46bbfed4ac24f /zellij-utils/src/input/layout.rs
parentfix(web): avoid sending single meta keypresses, cleanup (#4376) (diff)
downloadsl0ppij-3a26df6314cf5966ffb3065b97d4183b480d1441.tar.gz
sl0ppij-3a26df6314cf5966ffb3065b97d4183b480d1441.tar.xz
sl0ppij-3a26df6314cf5966ffb3065b97d4183b480d1441.zip
refactor(client-server-contract): config + layout (#4383)
* commented out ConfigWrittenToDisk instructions * commented out WriteConfigToDisk instructions * commented out FailedToWriteConfigToDisk and WriteConfigToDisk instructions * pass cli assets from client to server instead of parsed config - kind of working, lots of stuff still broken * move ClientAttributes to the server side * move ClientAttributes to the server side in Attach instruction as well * move CliArgs and runtime options from NewClient -> move them to the server * moved plugin_aliases to the server side * moved initial config writing to the server side * moved layout parsing to the server * some cleanups * move config file watching and live reload to the server * move config file writing to the server side * use saved config when attaching * get web server to work with the new config roles * some cleanups * moar cleanups * even moar cleanups * yet more cleanups * fix tests * style(fmt): rustfmt * style(fmt): rustfmt * fix e2e tests * docs(changelog): add PR
Diffstat (limited to 'zellij-utils/src/input/layout.rs')
-rw-r--r--zellij-utils/src/input/layout.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index e29ad94d..83704439 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -1248,6 +1248,50 @@ impl Layout {
}
layout
}
+ pub fn from_layout_info_with_config(
+ layout_dir: &Option<PathBuf>,
+ layout_info: &LayoutInfo,
+ config: Option<Config>,
+ ) -> Result<(Layout, Config), ConfigError> {
+ 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());
+ let (path_to_layout, stringified_layout, swap_layouts) =
+ Self::stringified_from_dir(
+ &PathBuf::from(layout_name_without_extension),
+ layout_dir.as_ref(),
+ )?;
+ (Some(path_to_layout), stringified_layout, swap_layouts)
+ },
+ LayoutInfo::BuiltIn(layout_name) => {
+ let (path_to_layout, stringified_layout, swap_layouts) =
+ Self::stringified_from_default_assets(&PathBuf::from(layout_name))?;
+ (Some(path_to_layout), stringified_layout, swap_layouts)
+ },
+ 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.clone(), None),
+ };
+ 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)));
+ }
+ let config = Config::from_kdl(&raw_layout, config)?; // this merges the two config, with
+ layout.map(|l| (l, config))
+ }
pub fn stringified_from_path_or_default(
layout_path: Option<&PathBuf>,
layout_dir: Option<PathBuf>,
@@ -1369,6 +1413,20 @@ impl Layout {
let config = Config::from_kdl(&raw_layout, Some(config))?; // this merges the two config, with
Ok((layout, config))
}
+ pub fn default_layout_asset() -> Layout {
+ Layout::from_kdl(
+ &Self::stringified_default_from_assets().unwrap(),
+ None,
+ Some((
+ "",
+ Self::stringified_default_swap_from_assets()
+ .unwrap()
+ .as_str(),
+ )),
+ None,
+ )
+ .unwrap()
+ }
pub fn from_str(
raw: &str,
path_to_raw_layout: String,