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());
|
||||
err_ctx.add_call(ContextType::StdinHandler);
|
||||
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();
|
||||
}
|
||||
loop {
|
||||
|
@ -560,7 +560,7 @@ pub(crate) fn screen_thread_main(
|
||||
config_options: Box<Options>,
|
||||
) {
|
||||
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(
|
||||
bus,
|
||||
|
@ -39,7 +39,7 @@ impl FromStr for OnForceClose {
|
||||
/// into Options and CliOptions, this could be a good canditate for a macro
|
||||
pub struct Options {
|
||||
/// 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)]
|
||||
#[serde(default)]
|
||||
pub simplified_ui: Option<bool>,
|
||||
@ -58,11 +58,13 @@ pub struct Options {
|
||||
pub layout_dir: Option<PathBuf>,
|
||||
#[structopt(long)]
|
||||
#[serde(default)]
|
||||
/// Disable handling of mouse events
|
||||
pub disable_mouse_mode: Option<bool>,
|
||||
/// Set the handling of mouse events (true or false)
|
||||
/// Can be temporarily bypassed by the [SHIFT] key
|
||||
pub mouse_mode: Option<bool>,
|
||||
#[structopt(long)]
|
||||
#[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)
|
||||
#[structopt(long)]
|
||||
pub on_force_close: Option<OnForceClose>,
|
||||
@ -81,8 +83,8 @@ impl Options {
|
||||
/// will supercede a `Some` in `self`
|
||||
// TODO: Maybe a good candidate for a macro?
|
||||
pub fn merge(&self, other: Options) -> Options {
|
||||
let disable_mouse_mode = other.disable_mouse_mode.or(self.disable_mouse_mode);
|
||||
let no_pane_frames = other.no_pane_frames.or(self.no_pane_frames);
|
||||
let mouse_mode = other.mouse_mode.or(self.mouse_mode);
|
||||
let pane_frames = other.pane_frames.or(self.pane_frames);
|
||||
let simplified_ui = other.simplified_ui.or(self.simplified_ui);
|
||||
let default_mode = other.default_mode.or(self.default_mode);
|
||||
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
||||
@ -96,8 +98,8 @@ impl Options {
|
||||
default_mode,
|
||||
default_shell,
|
||||
layout_dir,
|
||||
disable_mouse_mode,
|
||||
no_pane_frames,
|
||||
mouse_mode,
|
||||
pane_frames,
|
||||
on_force_close,
|
||||
}
|
||||
}
|
||||
@ -118,8 +120,8 @@ impl Options {
|
||||
};
|
||||
|
||||
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 no_pane_frames = merge_bool(other.no_pane_frames, self.no_pane_frames);
|
||||
let mouse_mode = merge_bool(other.mouse_mode, self.mouse_mode);
|
||||
let pane_frames = merge_bool(other.pane_frames, self.pane_frames);
|
||||
|
||||
let default_mode = other.default_mode.or(self.default_mode);
|
||||
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
|
||||
@ -133,8 +135,8 @@ impl Options {
|
||||
default_mode,
|
||||
default_shell,
|
||||
layout_dir,
|
||||
disable_mouse_mode,
|
||||
no_pane_frames,
|
||||
mouse_mode,
|
||||
pane_frames,
|
||||
on_force_close,
|
||||
}
|
||||
}
|
||||
@ -152,52 +154,36 @@ impl Options {
|
||||
/// Options that can be set through cli flags
|
||||
/// boolean flags end up toggling boolean options in `Options`
|
||||
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
|
||||
#[structopt(long, conflicts_with("mouse-mode"))]
|
||||
pub disable_mouse_mode: bool,
|
||||
#[structopt(long)]
|
||||
/// Disable display of pane frames
|
||||
#[structopt(long, conflicts_with("pane-frames"))]
|
||||
pub no_pane_frames: bool,
|
||||
/// Set behaviour on force close (quit or detach)
|
||||
#[structopt(long)]
|
||||
pub on_force_close: Option<OnForceClose>,
|
||||
#[structopt(flatten)]
|
||||
options: Options,
|
||||
}
|
||||
|
||||
impl From<CliOptions> for Options {
|
||||
fn from(cli_options: CliOptions) -> Self {
|
||||
let handle_bool = |bool| {
|
||||
if bool {
|
||||
Some(true)
|
||||
} else {
|
||||
None
|
||||
let mut opts = cli_options.options;
|
||||
|
||||
if cli_options.no_pane_frames {
|
||||
opts.pane_frames = Some(false);
|
||||
}
|
||||
if cli_options.disable_mouse_mode {
|
||||
opts.mouse_mode = Some(false);
|
||||
}
|
||||
};
|
||||
|
||||
Self {
|
||||
simplified_ui: handle_bool(cli_options.simplified_ui),
|
||||
theme: cli_options.theme,
|
||||
default_mode: cli_options.default_mode,
|
||||
default_shell: cli_options.default_shell,
|
||||
layout_dir: cli_options.layout_dir,
|
||||
disable_mouse_mode: handle_bool(cli_options.disable_mouse_mode),
|
||||
no_pane_frames: handle_bool(cli_options.no_pane_frames),
|
||||
on_force_close: cli_options.on_force_close,
|
||||
simplified_ui: opts.simplified_ui,
|
||||
theme: opts.theme,
|
||||
default_mode: opts.default_mode,
|
||||
default_shell: opts.default_shell,
|
||||
layout_dir: opts.layout_dir,
|
||||
mouse_mode: opts.mouse_mode,
|
||||
pane_frames: opts.pane_frames,
|
||||
on_force_close: opts.on_force_close,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ impl Setup {
|
||||
// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
||||
let hyperlink_start = "\u{1b}]8;;";
|
||||
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();
|
||||
|
||||
@ -315,7 +315,7 @@ impl Setup {
|
||||
|
||||
message.push_str(&format!("[ARROW SEPARATOR]: {}\n", ARROW_SEPARATOR));
|
||||
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();
|
||||
hyperlink_compat.push_str(hyperlink_start);
|
||||
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",
|
||||
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));
|
||||
let mut hyperlink = String::new();
|
||||
@ -334,7 +337,7 @@ impl Setup {
|
||||
hyperlink.push_str(hyperlink_mid);
|
||||
hyperlink.push_str("zellij.dev/documentation");
|
||||
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'
|
||||
|
||||
std::io::stdout().write_all(message.as_bytes())?;
|
||||
|
Loading…
Reference in New Issue
Block a user