diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-05-15 18:42:23 +0200 |
---|---|---|
committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-16 12:43:50 +0200 |
commit | abf0a2d0c624046d4660000b8b16acabe7cb5b6e (patch) | |
tree | 628d67160b1e303eede34251e4bef5e6dadafa03 /src | |
parent | b835594bf2d87e30829b2f83fe85b4c6d5efa57e (diff) |
Split Layout Flag
* Split Layout Flag into `layout` that searches in default layout
directories and `layout-path` that takes a path to a layout file
Close #506.
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.rs | 6 | ||||
-rw-r--r-- | src/client/layout.rs | 15 | ||||
-rw-r--r-- | src/server/mod.rs | 7 | ||||
-rw-r--r-- | src/tests/integration/layouts.rs | 2 |
4 files changed, 15 insertions, 15 deletions
diff --git a/src/cli.rs b/src/cli.rs index 69496808b..206ebe9d3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -16,10 +16,14 @@ pub struct CliArgs { #[structopt(long)] pub data_dir: Option<PathBuf>, - /// Path to a layout yaml file + /// Name of a layout yaml file inside the plugin directory #[structopt(short, long)] pub layout: Option<PathBuf>, + /// Path to a layout yaml file + #[structopt(long, parse(from_os_str))] + pub layout_path: Option<PathBuf>, + /// Change where zellij looks for the configuration #[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV)] pub config: Option<PathBuf>, diff --git a/src/client/layout.rs b/src/client/layout.rs index 3648ece90..592481dce 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 a4a79ca0f..076d232d0 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 bd7ceb3fc..f3848461f 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", )); |