From abf0a2d0c624046d4660000b8b16acabe7cb5b6e Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sat, 15 May 2021 18:42:23 +0200 Subject: [PATCH 1/2] 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. --- src/cli.rs | 6 +++++- src/client/layout.rs | 15 ++++----------- src/server/mod.rs | 7 +++++-- src/tests/integration/layouts.rs | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) 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", )); From dc067580f3df50bff17aee48fb330c164084c6bd Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 18 May 2021 09:45:03 +0200 Subject: [PATCH 2/2] Fix Clippy Suggestions --- src/client/mod.rs | 4 ++-- src/common/ipc.rs | 2 +- src/common/screen.rs | 5 ++++- src/server/mod.rs | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 862c13cc..f148a50a 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -88,8 +88,8 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C os_input.connect_to_server(&*ZELLIJ_IPC_PIPE); os_input.send_to_server(ClientToServerMsg::NewClient( full_screen_ws, - opts, - config_options, + Box::new(opts), + Box::new(config_options), )); os_input.set_raw_mode(0); let _ = os_input diff --git a/src/common/ipc.rs b/src/common/ipc.rs index 129727a1..af6dd859 100644 --- a/src/common/ipc.rs +++ b/src/common/ipc.rs @@ -47,7 +47,7 @@ pub enum ClientToServerMsg { DisconnectFromSession,*/ ClientExit, TerminalResize(PositionAndSize), - NewClient(PositionAndSize, CliArgs, Options), + NewClient(PositionAndSize, Box, Box), Action(Action), } diff --git a/src/common/screen.rs b/src/common/screen.rs index 62fcec19..d2030243 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -325,11 +325,14 @@ impl Screen { } } +// The box is here in order to make the +// NewClient enum smaller +#[allow(clippy::boxed_local)] pub fn screen_thread_main( bus: Bus, max_panes: Option, full_screen_ws: PositionAndSize, - config_options: Options, + config_options: Box, ) { let colors = bus.os_input.as_ref().unwrap().load_palette(); let capabilities = config_options.simplified_ui; diff --git a/src/server/mod.rs b/src/server/mod.rs index fdaeead1..12cc2229 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -27,7 +27,7 @@ use route::route_thread_main; /// ones sent by client to server #[derive(Debug, Clone)] pub enum ServerInstruction { - NewClient(PositionAndSize, CliArgs, Options), + NewClient(PositionAndSize, Box, Box), Render(Option), UnblockInputThread, ClientExit, @@ -186,8 +186,8 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { fn init_session( os_input: Box, - opts: CliArgs, - config_options: Options, + opts: Box, + config_options: Box, to_server: SenderWithContext, full_screen_ws: PositionAndSize, ) -> SessionMetaData {