diff --git a/src/cli.rs b/src/cli.rs index 69496808..206ebe9d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -16,10 +16,14 @@ pub struct CliArgs { #[structopt(long)] pub data_dir: Option, - /// Path to a layout yaml file + /// Name of a layout yaml file inside the plugin directory #[structopt(short, long)] pub layout: Option, + /// Path to a layout yaml file + #[structopt(long, parse(from_os_str))] + pub layout_path: Option, + /// Change where zellij looks for the configuration #[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV)] pub config: Option, diff --git a/src/client/layout.rs b/src/client/layout.rs index 3648ece9..592481dc 100644 --- a/src/client/layout.rs +++ b/src/client/layout.rs @@ -190,10 +190,9 @@ pub struct Layout { } impl Layout { - pub fn new(layout_path: &Path, data_dir: &Path) -> Self { - let layout_dir = data_dir.join("layouts/"); + pub fn new(layout_path: &Path) -> Self { let mut layout_file = File::open(&layout_path) - .or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml"))) + .or_else(|_| File::open(&layout_path.with_extension("yaml"))) .unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display())); let mut layout = String::new(); @@ -207,14 +206,8 @@ impl Layout { // It wants to use Path here, but that doesn't compile. #[allow(clippy::ptr_arg)] - pub fn from_defaults(layout_path: &PathBuf, data_dir: &Path) -> Self { - Self::new( - &data_dir - .join("layouts/") - .join(layout_path) - .with_extension("yaml"), - &data_dir, - ) + pub fn from_dir(layout: &PathBuf, data_dir: &Path) -> Self { + Self::new(&data_dir.join("layouts/").join(layout)) } pub fn total_terminal_panes(&self) -> usize { diff --git a/src/server/mod.rs b/src/server/mod.rs index a4a79ca0..076d232d 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -195,10 +195,13 @@ fn init_session( let default_layout = Some(PathBuf::from("default")); #[cfg(test)] let default_layout = None; + let layout_path = opts.layout_path; let maybe_layout = opts .layout - .map(|p| Layout::new(&p, &data_dir)) - .or_else(|| default_layout.map(|p| Layout::from_defaults(&p, &data_dir))); + .as_ref() + .map(|p| Layout::from_dir(&p, &data_dir)) + .or_else(|| layout_path.map(|p| Layout::new(&p))) + .or_else(|| default_layout.map(|p| Layout::from_dir(&p, &data_dir))); let pty_thread = thread::Builder::new() .name("pty".to_string()) diff --git a/src/tests/integration/layouts.rs b/src/tests/integration/layouts.rs index bd7ceb3f..f3848461 100644 --- a/src/tests/integration/layouts.rs +++ b/src/tests/integration/layouts.rs @@ -24,7 +24,7 @@ pub fn accepts_basic_layout() { let mut fake_input_output = get_fake_os_input(&fake_win_size); fake_input_output.add_terminal_input(&[&QUIT]); let mut opts = CliArgs::default(); - opts.layout = Some(PathBuf::from( + opts.layout_path = Some(PathBuf::from( "src/tests/fixtures/layouts/three-panes-with-nesting.yaml", ));