Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(options): handling and overwriting cli opts #859

Merged
merged 2 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zellij-client/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
84 changes: 35 additions & 49 deletions zellij-utils/src/input/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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>,
Expand All @@ -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());
Expand All @@ -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,
}
}
Expand All @@ -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());
Expand All @@ -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,
}
}
Expand All @@ -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,
}
}
}
9 changes: 6 additions & 3 deletions zellij-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand All @@ -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())?;
Expand Down