diff options
| author | har7an <99636919+har7an@users.noreply.github.com> | 2026-01-26 18:05:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-26 18:05:51 +0000 |
| commit | bdf20eef50f2d68501be708ec5ee38dbe9366a91 (patch) | |
| tree | e97215a9464d322eb65e416b1662c530e44d57f1 /zellij-utils/src/setup.rs | |
| parent | fix: get "zellij run --session" to also work on sessions that have no attache... (diff) | |
| download | sl0ppij-bdf20eef50f2d68501be708ec5ee38dbe9366a91.tar.gz sl0ppij-bdf20eef50f2d68501be708ec5ee38dbe9366a91.tar.xz sl0ppij-bdf20eef50f2d68501be708ec5ee38dbe9366a91.zip | |
Fix loading short layouts and custom config dirs (#4640)
* test(e2e): Write a regression test to validate behavior
w.r.t. loading and determining the session layout file. Compared to
release v0.43.1, right now there is a problem where `zellij --layout
NAME`, with `NAME` being the filename of a layout in the
`$ZELLIJ_DATA_DIR/layouts/` subfolder, doesn't resolve to the correct
layout file. Instead, zellij will silently fall back to its default
config. It does, however, recognize nonexistent configuration files.
* fix(utils): Treat bare layout names as file paths first
before defaulting to builtin layout names. This restores the behavior
shown by zellij up until 0.43.1, which was altered in a recent extension
of the server-client API.
* fix: Forward client layout information to startup code
and ensure it isn't ignored along the way. Update a bunch of tests to
react to the new function interface and write new tests to catch
deviations in the future.
* test: Fix misconfigured e2e test
to ensure that a custom `--config-dir` is indeed respected during
application startup.
* test: Rewrite config dir test to not use variable metadata
since the `LayoutInfo` object previously dumped into the snapshot
contains information that isn't platform agnostic, including an absolute
file path and a timestamp.
* docs(CHANGELOG): Mention PR #4640
in the list of changes for the next release.
* fix: Handle bare layouts with name "default" correctly
and assume a "default" layout if no layout name is given during layout
resolution. "default" may not always be the builtin default layout,
since users can write their own "default.kdl" that takes effect when
placed in the layout directory an no other layouts are explicitly
specified.
Diffstat (limited to 'zellij-utils/src/setup.rs')
| -rw-r--r-- | zellij-utils/src/setup.rs | 85 |
1 files changed, 66 insertions, 19 deletions
diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 2be6cdef..ac672f5d 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -8,6 +8,7 @@ use crate::{ FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_CACHE_DIR, ZELLIJ_DEFAULT_THEMES, ZELLIJ_PROJ_DIR, }, + data::LayoutInfo, errors::prelude::*, home::*, input::{ @@ -368,7 +369,7 @@ impl Setup { /// 3. config options (`config.kdl`) pub fn from_cli_args( cli_args: &CliArgs, - ) -> Result<(Config, Layout, Options, Config, Options), ConfigError> { + ) -> Result<(Config, Option<LayoutInfo>, Options, Config, Options), ConfigError> { // note that this can potentially exit the process Setup::handle_setup_commands(cli_args); let config = Config::try_from(cli_args)?; @@ -384,7 +385,7 @@ impl Setup { let cli_config_options = merge_attach_command_options(cli_config_options, &cli_args); let mut config_without_layout = config.clone(); - let (layout, mut config) = + let (layout_info, mut config) = Setup::parse_layout_and_override_config(cli_config_options.as_ref(), config, cli_args)?; let config_options = @@ -426,7 +427,7 @@ impl Setup { }; Ok(( config, - layout, + layout_info, config_options, config_without_layout, config_options_without_layout, @@ -666,15 +667,16 @@ impl Setup { cli_config_options: Option<&Options>, config: Config, cli_args: &CliArgs, - ) -> Result<(Layout, Config), ConfigError> { + ) -> Result<(Option<LayoutInfo>, Config), ConfigError> { // find the layout folder relative to which we'll look for our layout let layout_dir = cli_config_options .as_ref() .and_then(|cli_options| cli_options.layout_dir.clone()) .or_else(|| config.options.layout_dir.clone()) - .or_else(|| { - get_layout_dir(cli_args.config_dir.clone().or_else(find_default_config_dir)) - }); + .or_else(|| get_layout_dir(cli_args.config_dir.clone())) + .or_else(|| get_layout_dir(find_default_config_dir())) + // Try to get an absolute path, else let the resolution code figure this out. + .map(|d| d.canonicalize().unwrap_or(d)); // the chosen layout can either be a path relative to the layout_dir or a name of one // of our assets, this distinction is made when parsing the layout - TODO: ideally, this // logic should not be split up and all the decisions should happen here @@ -687,6 +689,7 @@ impl Setup { .and_then(|cli_options| cli_options.default_layout.clone()) }) .or_else(|| config.options.default_layout.clone()); + let layout_info = LayoutInfo::from_config(&layout_dir, &chosen_layout); if let Some(layout_url) = chosen_layout .as_ref() .and_then(|l| l.to_str()) @@ -698,11 +701,12 @@ impl Setup { } }) { - Layout::from_url(layout_url, config) + Layout::from_url(layout_url, config).map(|(_layout, config)| (layout_info, config)) } else { // we merge-override the config here because the layout might contain configuration // that needs to take precedence Layout::from_path_or_default(chosen_layout.as_ref(), layout_dir.clone(), config) + .map(|(_layout, config)| (layout_info, config)) } } fn handle_setup_commands(cli_args: &CliArgs) { @@ -744,6 +748,7 @@ fn merge_attach_command_options( mod setup_test { use super::Setup; use crate::cli::{CliArgs, Command}; + use crate::data::LayoutInfo; use crate::input::options::Options; use insta::assert_snapshot; use std::path::PathBuf; @@ -751,9 +756,9 @@ mod setup_test { #[test] fn default_config_with_no_cli_arguments() { let cli_args = CliArgs::default(); - let (config, layout, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (config, layout_info, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); - assert_snapshot!(format!("{:#?}", layout)); + assert_snapshot!(format!("{:#?}", layout_info)); assert_snapshot!(format!("{:#?}", options)); } #[test] @@ -763,7 +768,7 @@ mod setup_test { simplified_ui: Some(true), ..Default::default() })); - let (_config, _layout, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (_config, _layout_info, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", options)); } #[test] @@ -773,9 +778,9 @@ mod setup_test { "{}/src/test-fixtures/layout-with-options.kdl", env!("CARGO_MANIFEST_DIR") ))); - let (_config, layout, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (_config, layout_info, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", options)); - assert_snapshot!(format!("{:#?}", layout)); + assert_snapshot!(format!("{:#?}", layout_info)); } #[test] fn cli_arguments_override_layout_options() { @@ -788,9 +793,9 @@ mod setup_test { pane_frames: Some(true), ..Default::default() })); - let (_config, layout, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (_config, layout_info, options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", options)); - assert_snapshot!(format!("{:#?}", layout)); + assert_snapshot!(format!("{:#?}", layout_info)); } #[test] fn layout_env_vars_override_config_env_vars() { @@ -803,7 +808,7 @@ mod setup_test { "{}/src/test-fixtures/layout-with-env-vars.kdl", env!("CARGO_MANIFEST_DIR") ))); - let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (config, _layout_info, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); } #[test] @@ -817,7 +822,7 @@ mod setup_test { "{}/src/test-fixtures/layout-with-ui-config.kdl", env!("CARGO_MANIFEST_DIR") ))); - let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (config, _layout_info, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); } #[test] @@ -831,7 +836,7 @@ mod setup_test { "{}/src/test-fixtures/layout-with-themes-config.kdl", env!("CARGO_MANIFEST_DIR") ))); - let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (config, _layout_info, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); } #[test] @@ -845,7 +850,49 @@ mod setup_test { "{}/src/test-fixtures/layout-with-keybindings-config.kdl", env!("CARGO_MANIFEST_DIR") ))); - let (config, _layout, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let (config, _layout_info, _options, _, _) = Setup::from_cli_args(&cli_args).unwrap(); assert_snapshot!(format!("{:#?}", config)); } + #[test] + fn cli_config_dir_overrides_defaults() { + let cli_args = CliArgs { + config_dir: Some(PathBuf::from(format!( + "{}/src/test-fixtures/config-dirs/layout-upside-down", + env!("CARGO_MANIFEST_DIR") + ))), + ..Default::default() + }; + let (_, layout_info, _, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let Some(LayoutInfo::File(layout_path, _)) = layout_info else { + panic!("layout info has unexpected format"); + }; + assert_eq!( + layout_path, + format!( + "{}/src/test-fixtures/config-dirs/layout-upside-down/layouts/upside-down.kdl", + env!("CARGO_MANIFEST_DIR") + ) + ); + } + #[test] + fn cli_config_dir_finds_custom_default() { + let cli_args = CliArgs { + config_dir: Some(PathBuf::from(format!( + "{}/src/test-fixtures/config-dirs/custom-default-layout", + env!("CARGO_MANIFEST_DIR") + ))), + ..Default::default() + }; + let (_, layout_info, _, _, _) = Setup::from_cli_args(&cli_args).unwrap(); + let Some(LayoutInfo::File(layout_path, _)) = layout_info else { + panic!("layout info has unexpected format"); + }; + assert_eq!( + layout_path, + format!( + "{}/src/test-fixtures/config-dirs/custom-default-layout/layouts/default.kdl", + env!("CARGO_MANIFEST_DIR") + ) + ); + } } |
