From 337674b0736f275c579f3355aa12c8900ccccfe9 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 9 Jul 2021 11:55:33 +0200 Subject: [PATCH 1/5] Improve clarity of precedence in options --- zellij-utils/src/input/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index 461f5c34..cdb61a85 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -32,7 +32,7 @@ impl FromStr for OnForceClose { #[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)] /// Options that can be set either through the config file, -/// or cli flags +/// or cli flags - cli flags should take precedence over the config file pub struct Options { /// Allow plugins to use a more simplified layout /// that is compatible with more fonts From 6299660d5caf294d10ddaf5c6df44ee14889a5f7 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 9 Jul 2021 11:57:52 +0200 Subject: [PATCH 2/5] Add doc-comment for mouse-mode --- zellij-utils/src/input/options.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index cdb61a85..c2f2ba55 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -54,6 +54,7 @@ pub struct Options { pub layout_dir: Option, #[structopt(long)] #[serde(default)] + /// Disable handling of mouse events pub disable_mouse_mode: bool, /// Set behaviour on force close (quit or detach) #[structopt(long)] From 89f84ecd3f1a1573d0f3d8e0c46426d162f2b2e4 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 9 Jul 2021 13:09:05 +0200 Subject: [PATCH 3/5] Simplify merging of options --- zellij-utils/src/input/options.rs | 42 ++++++------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index c2f2ba55..714e6524 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -74,42 +74,16 @@ impl Options { /// will supercede a `Some` in `self` // TODO: Maybe a good candidate for a macro? pub fn merge(&self, other: Options) -> Options { - let simplified_ui = if other.simplified_ui { - true - } else { - self.simplified_ui - }; + let merge_bool = |opt_other, opt_self| if opt_other { true } else { opt_self }; - let default_mode = match other.default_mode { - None => self.default_mode, - other => other, - }; + let simplified_ui = merge_bool(other.simplified_ui, self.simplified_ui); + let disable_mouse_mode = merge_bool(other.disable_mouse_mode, self.disable_mouse_mode); - let default_shell = match other.default_shell { - None => self.default_shell.clone(), - other => other, - }; - - let layout_dir = match other.layout_dir { - None => self.layout_dir.clone(), - other => other, - }; - - let theme = match other.theme { - None => self.theme.clone(), - other => other, - }; - - let disable_mouse_mode = if other.disable_mouse_mode { - true - } else { - self.disable_mouse_mode - }; - - let on_force_close = match other.on_force_close { - None => self.on_force_close, - other => other, - }; + let default_mode = other.default_mode.or(self.default_mode); + let default_shell = other.default_shell.or_else(|| self.default_shell.clone()); + let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone()); + let theme = other.theme.or_else(|| self.theme.clone()); + let on_force_close = other.on_force_close.or(self.on_force_close); Options { simplified_ui, From cf8d5a7a4d7ad6bc350292b3fa1f583d04b21e6c Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 9 Jul 2021 13:11:02 +0200 Subject: [PATCH 4/5] Use lowercase for options --- zellij-utils/assets/config/default.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zellij-utils/assets/config/default.yaml b/zellij-utils/assets/config/default.yaml index 9b0a57ff..d9090a8d 100644 --- a/zellij-utils/assets/config/default.yaml +++ b/zellij-utils/assets/config/default.yaml @@ -244,6 +244,6 @@ keybinds: # Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP # eg. when terminal window with an active zellij session is closed # Options: -# - Detach (Default) -# - Quit -#on_force_close: Quit +# - detach (Default) +# - quit +#on_force_close: quit From 8363705939dd35d25832db0b536b250d29d924a1 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 9 Jul 2021 15:01:05 +0200 Subject: [PATCH 5/5] Add serde-alias for on_force_close * It doesn't deserialize from the configuration otherwise, if specified in lower-case. Alternative: use a rename. --- zellij-utils/src/input/options.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index 714e6524..a2f9231c 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -8,7 +8,9 @@ use zellij_tile::data::InputMode; #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum OnForceClose { + #[serde(alias = "quit")] Quit, + #[serde(alias = "detach")] Detach, }