diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-07-09 17:25:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 17:25:27 +0200 |
commit | 22b30599d8d094dced8b3b02c7ebca9323bb895b (patch) | |
tree | 3048810d4eaabbf043c9a99e1db626831a42ebf9 /zellij-utils | |
parent | f755ef23d97f495231e22ddaa364772da32f648f (diff) | |
parent | 8363705939dd35d25832db0b536b250d29d924a1 (diff) |
Merge pull request #612 from a-kenji/improve-options
Improve options
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/assets/config/default.yaml | 6 | ||||
-rw-r--r-- | zellij-utils/src/input/options.rs | 47 |
2 files changed, 15 insertions, 38 deletions
diff --git a/zellij-utils/assets/config/default.yaml b/zellij-utils/assets/config/default.yaml index 9b0a57ffa..d9090a8dc 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 diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index 461f5c341..a2f9231cd 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, } @@ -32,7 +34,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 @@ -54,6 +56,7 @@ pub struct Options { pub layout_dir: Option<PathBuf>, #[structopt(long)] #[serde(default)] + /// Disable handling of mouse events pub disable_mouse_mode: bool, /// Set behaviour on force close (quit or detach) #[structopt(long)] @@ -73,42 +76,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 default_mode = match other.default_mode { - None => self.default_mode, - other => other, - }; - - let default_shell = match other.default_shell { - None => self.default_shell.clone(), - other => other, - }; + let merge_bool = |opt_other, opt_self| if opt_other { true } else { opt_self }; - 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 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 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, |