mirror of
https://github.com/zellij-org/zellij.git
synced 2024-11-26 22:15:19 +03:00
fix(options): handling and overwriting cli opts (#859)
* fix(options): handling ond verwriting cli opts * previously it was only possible to turn off certain features with a command line option, now it is possible to also overwrite this behavior in a sane way, for that some breaking changes happened: following options got renamed and inverted: ``` disable_mouse_mode -> mouse_mode no_pane_frames -> pane_frames ``` following cli options got added: ``` mouse-mode [bool] pane-frames [bool] simplified-ui [bool] ``` the following cli flag got removed: ``` simplified-ui ``` They can be specified in the following way: ``` zellij options --mouse-mode true ``` in order to enable the mouse mode, even if it is turned off in the config file: ``` mouse_mode: false ``` The order is now as follows: 1. corresponding flag (`disable-mouse-mode`) 2. corresponding option (`mouse-mode`) 3. corresponding config option (`mouse_mode`) * add: options and flags for the same value conflict * example: ``` zellij options --mouse-mode true --disable-mouse-mode` ``` ``` $ error: The argument '--mouse-mode <mouse-mode>' cannot be used with '--disable-mouse-mode' ```
This commit is contained in:
parent
26bd80be2d
commit
bd8c834d7c
@ -63,7 +63,7 @@ impl InputHandler {
|
|||||||
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
|
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
|
||||||
err_ctx.add_call(ContextType::StdinHandler);
|
err_ctx.add_call(ContextType::StdinHandler);
|
||||||
let alt_left_bracket = vec![27, 91];
|
let alt_left_bracket = vec![27, 91];
|
||||||
if !self.options.disable_mouse_mode.unwrap_or_default() {
|
if self.options.mouse_mode.unwrap_or(true) {
|
||||||
self.os_input.enable_mouse();
|
self.os_input.enable_mouse();
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
|
@ -560,7 +560,7 @@ pub(crate) fn screen_thread_main(
|
|||||||
config_options: Box<Options>,
|
config_options: Box<Options>,
|
||||||
) {
|
) {
|
||||||
let capabilities = config_options.simplified_ui;
|
let capabilities = config_options.simplified_ui;
|
||||||
let draw_pane_frames = !config_options.no_pane_frames.unwrap_or_default();
|
let draw_pane_frames = config_options.pane_frames.unwrap_or(true);
|
||||||
|
|
||||||
let mut screen = Screen::new(
|
let mut screen = Screen::new(
|
||||||
bus,
|
bus,
|
||||||
|
@ -39,7 +39,7 @@ impl FromStr for OnForceClose {
|
|||||||
/// into Options and CliOptions, this could be a good canditate for a macro
|
/// into Options and CliOptions, this could be a good canditate for a macro
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
/// Allow plugins to use a more simplified layout
|
/// Allow plugins to use a more simplified layout
|
||||||
/// that is compatible with more fonts
|
/// that is compatible with more fonts (true or false)
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub simplified_ui: Option<bool>,
|
pub simplified_ui: Option<bool>,
|
||||||
@ -58,11 +58,13 @@ pub struct Options {
|
|||||||
pub layout_dir: Option<PathBuf>,
|
pub layout_dir: Option<PathBuf>,
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
/// Disable handling of mouse events
|
/// Set the handling of mouse events (true or false)
|
||||||
pub disable_mouse_mode: Option<bool>,
|
/// Can be temporarily bypassed by the [SHIFT] key
|
||||||
|
pub mouse_mode: Option<bool>,
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub no_pane_frames: Option<bool>,
|
/// Set display of the pane frames (true or false)
|
||||||
|
pub pane_frames: Option<bool>,
|
||||||
/// Set behaviour on force close (quit or detach)
|
/// Set behaviour on force close (quit or detach)
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub on_force_close: Option<OnForceClose>,
|
pub on_force_close: Option<OnForceClose>,
|
||||||
@ -81,8 +83,8 @@ impl Options {
|
|||||||
/// will supercede a `Some` in `self`
|
/// will supercede a `Some` in `self`
|
||||||
// TODO: Maybe a good candidate for a macro?
|
// TODO: Maybe a good candidate for a macro?
|
||||||
pub fn merge(&self, other: Options) -> Options {
|
pub fn merge(&self, other: Options) -> Options {
|
||||||
let disable_mouse_mode = other.disable_mouse_mode.or(self.disable_mouse_mode);
|
let mouse_mode = other.mouse_mode.or(self.mouse_mode);
|
||||||
let no_pane_frames = other.no_pane_frames.or(self.no_pane_frames);
|
let pane_frames = other.pane_frames.or(self.pane_frames);
|
||||||
let simplified_ui = other.simplified_ui.or(self.simplified_ui);
|
let simplified_ui = other.simplified_ui.or(self.simplified_ui);
|
||||||
let default_mode = other.default_mode.or(self.default_mode);
|
let default_mode = other.default_mode.or(self.default_mode);
|
||||||
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
||||||
@ -96,8 +98,8 @@ impl Options {
|
|||||||
default_mode,
|
default_mode,
|
||||||
default_shell,
|
default_shell,
|
||||||
layout_dir,
|
layout_dir,
|
||||||
disable_mouse_mode,
|
mouse_mode,
|
||||||
no_pane_frames,
|
pane_frames,
|
||||||
on_force_close,
|
on_force_close,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,8 +120,8 @@ impl Options {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let simplified_ui = merge_bool(other.simplified_ui, self.simplified_ui);
|
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 mouse_mode = merge_bool(other.mouse_mode, self.mouse_mode);
|
||||||
let no_pane_frames = merge_bool(other.no_pane_frames, self.no_pane_frames);
|
let pane_frames = merge_bool(other.pane_frames, self.pane_frames);
|
||||||
|
|
||||||
let default_mode = other.default_mode.or(self.default_mode);
|
let default_mode = other.default_mode.or(self.default_mode);
|
||||||
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
||||||
@ -133,8 +135,8 @@ impl Options {
|
|||||||
default_mode,
|
default_mode,
|
||||||
default_shell,
|
default_shell,
|
||||||
layout_dir,
|
layout_dir,
|
||||||
disable_mouse_mode,
|
mouse_mode,
|
||||||
no_pane_frames,
|
pane_frames,
|
||||||
on_force_close,
|
on_force_close,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,52 +154,36 @@ impl Options {
|
|||||||
/// Options that can be set through cli flags
|
/// Options that can be set through cli flags
|
||||||
/// boolean flags end up toggling boolean options in `Options`
|
/// boolean flags end up toggling boolean options in `Options`
|
||||||
pub struct CliOptions {
|
pub struct CliOptions {
|
||||||
/// Allow plugins to use a more simplified layout
|
|
||||||
/// that is compatible with more fonts
|
|
||||||
#[structopt(long)]
|
|
||||||
pub simplified_ui: bool,
|
|
||||||
/// Set the default theme
|
|
||||||
#[structopt(long)]
|
|
||||||
pub theme: Option<String>,
|
|
||||||
/// Set the default mode
|
|
||||||
#[structopt(long)]
|
|
||||||
pub default_mode: Option<InputMode>,
|
|
||||||
/// Set the default shell
|
|
||||||
#[structopt(long, parse(from_os_str))]
|
|
||||||
pub default_shell: Option<PathBuf>,
|
|
||||||
/// Set the layout_dir, defaults to
|
|
||||||
/// subdirectory of config dir
|
|
||||||
#[structopt(long, parse(from_os_str))]
|
|
||||||
pub layout_dir: Option<PathBuf>,
|
|
||||||
#[structopt(long)]
|
|
||||||
/// Disable handling of mouse events
|
/// Disable handling of mouse events
|
||||||
|
#[structopt(long, conflicts_with("mouse-mode"))]
|
||||||
pub disable_mouse_mode: bool,
|
pub disable_mouse_mode: bool,
|
||||||
#[structopt(long)]
|
/// Disable display of pane frames
|
||||||
|
#[structopt(long, conflicts_with("pane-frames"))]
|
||||||
pub no_pane_frames: bool,
|
pub no_pane_frames: bool,
|
||||||
/// Set behaviour on force close (quit or detach)
|
#[structopt(flatten)]
|
||||||
#[structopt(long)]
|
options: Options,
|
||||||
pub on_force_close: Option<OnForceClose>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CliOptions> for Options {
|
impl From<CliOptions> for Options {
|
||||||
fn from(cli_options: CliOptions) -> Self {
|
fn from(cli_options: CliOptions) -> Self {
|
||||||
let handle_bool = |bool| {
|
let mut opts = cli_options.options;
|
||||||
if bool {
|
|
||||||
Some(true)
|
if cli_options.no_pane_frames {
|
||||||
} else {
|
opts.pane_frames = Some(false);
|
||||||
None
|
}
|
||||||
}
|
if cli_options.disable_mouse_mode {
|
||||||
};
|
opts.mouse_mode = Some(false);
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
simplified_ui: handle_bool(cli_options.simplified_ui),
|
simplified_ui: opts.simplified_ui,
|
||||||
theme: cli_options.theme,
|
theme: opts.theme,
|
||||||
default_mode: cli_options.default_mode,
|
default_mode: opts.default_mode,
|
||||||
default_shell: cli_options.default_shell,
|
default_shell: opts.default_shell,
|
||||||
layout_dir: cli_options.layout_dir,
|
layout_dir: opts.layout_dir,
|
||||||
disable_mouse_mode: handle_bool(cli_options.disable_mouse_mode),
|
mouse_mode: opts.mouse_mode,
|
||||||
no_pane_frames: handle_bool(cli_options.no_pane_frames),
|
pane_frames: opts.pane_frames,
|
||||||
on_force_close: cli_options.on_force_close,
|
on_force_close: opts.on_force_close,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ impl Setup {
|
|||||||
// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
||||||
let hyperlink_start = "\u{1b}]8;;";
|
let hyperlink_start = "\u{1b}]8;;";
|
||||||
let hyperlink_mid = "\u{1b}\\";
|
let hyperlink_mid = "\u{1b}\\";
|
||||||
let hyperlink_end = "\u{1b}]8;;\u{1b}\\\n'";
|
let hyperlink_end = "\u{1b}]8;;\u{1b}\\";
|
||||||
|
|
||||||
let mut message = String::new();
|
let mut message = String::new();
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ impl Setup {
|
|||||||
|
|
||||||
message.push_str(&format!("[ARROW SEPARATOR]: {}\n", ARROW_SEPARATOR));
|
message.push_str(&format!("[ARROW SEPARATOR]: {}\n", ARROW_SEPARATOR));
|
||||||
message.push_str(" Is the [ARROW_SEPARATOR] displayed correctly?\n");
|
message.push_str(" Is the [ARROW_SEPARATOR] displayed correctly?\n");
|
||||||
message.push_str(" If not you may want to either start zellij with a compatible mode 'zellij options --simplified-ui'\n");
|
message.push_str(" If not you may want to either start zellij with a compatible mode: 'zellij options --simplified-ui true'\n");
|
||||||
let mut hyperlink_compat = String::new();
|
let mut hyperlink_compat = String::new();
|
||||||
hyperlink_compat.push_str(hyperlink_start);
|
hyperlink_compat.push_str(hyperlink_start);
|
||||||
hyperlink_compat.push_str("https://zellij.dev/documentation/compatibility.html#the-status-bar-fonts-dont-render-correctly");
|
hyperlink_compat.push_str("https://zellij.dev/documentation/compatibility.html#the-status-bar-fonts-dont-render-correctly");
|
||||||
@ -326,6 +326,9 @@ impl Setup {
|
|||||||
" Or check the font that is in use:\n {}\n",
|
" Or check the font that is in use:\n {}\n",
|
||||||
hyperlink_compat
|
hyperlink_compat
|
||||||
));
|
));
|
||||||
|
message.push_str("[MOUSE INTERACTION]: \n");
|
||||||
|
message.push_str(" Can be temporarily disabled through pressing the [SHIFT] key.\n");
|
||||||
|
message.push_str(" If that doesn't fix any issues consider to disable the mouse handling of zellij: 'zellij options --disable-mouse-mode'\n");
|
||||||
|
|
||||||
message.push_str(&format!("[FEATURES]: {:?}\n", FEATURES));
|
message.push_str(&format!("[FEATURES]: {:?}\n", FEATURES));
|
||||||
let mut hyperlink = String::new();
|
let mut hyperlink = String::new();
|
||||||
@ -334,7 +337,7 @@ impl Setup {
|
|||||||
hyperlink.push_str(hyperlink_mid);
|
hyperlink.push_str(hyperlink_mid);
|
||||||
hyperlink.push_str("zellij.dev/documentation");
|
hyperlink.push_str("zellij.dev/documentation");
|
||||||
hyperlink.push_str(hyperlink_end);
|
hyperlink.push_str(hyperlink_end);
|
||||||
message.push_str(&format!("[DOCUMENTATION]: {}", hyperlink));
|
message.push_str(&format!("[DOCUMENTATION]: {}\n", hyperlink));
|
||||||
//printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
|
//printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
|
||||||
|
|
||||||
std::io::stdout().write_all(message.as_bytes())?;
|
std::io::stdout().write_all(message.as_bytes())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user