From 1b3092ae7c04bfaac9623b3aa746bb0299f53919 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Tue, 14 Nov 2023 20:27:14 +0100 Subject: [PATCH] Move to clearer reedline keyboard enhancement API (#11045) Go from the ill-defined `enable/disable` pairs to `.use_...` builders This alleviates unclear properties when the underlying enhancements are enabled. Now they are enabed when entering `Reedline::read_line` and disabled when exiting that. Furthermore allow setting `$env.config.use_kitty_protocol` to have an effect when toggling during runtime. Previously it was only enabled when receiving a value from `config.nu`. I kept the warning code there to not pollute the log. We could move it into the REPL-loop if desired Not sure if we should actively block the enabling of `bracketed_paste` on Windows. Need to test what happens if it just doesn't do anything we could remove the `cfg!` switch. At least for WSL2 Windows Terminal already supports bracketed paste. `target_os = windows` is a bad predictor for `conhost.exe`. Depends on https://github.com/nushell/reedline/pull/659 (pointing to personal fork) Closes https://github.com/nushell/nushell/issues/10982 Supersedes https://github.com/nushell/nushell/pull/10998 --- Cargo.lock | 2 +- crates/nu-cli/src/repl.rs | 26 +++++++------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9fedde256fc..d54d844d3bc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4300,7 +4300,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.25.0" -source = "git+https://github.com/nushell/reedline.git?branch=main#973dbb5f5f2338c18c25ce951bfa42c8d8cacfdf" +source = "git+https://github.com/nushell/reedline.git?branch=main#879272643fd4ba3409429052aca9a8cd56ba3dab" dependencies = [ "chrono", "crossterm 0.27.0", diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 90138a5dbd45..d79198f0570f 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -108,16 +108,8 @@ pub fn evaluate_repl( use_color, ); - let config = engine_state.get_config(); - if config.bracketed_paste { - // try to enable bracketed paste - // It doesn't work on windows system: https://github.com/crossterm-rs/crossterm/issues/737 - #[cfg(not(target_os = "windows"))] - let _ = line_editor.enable_bracketed_paste(); - } - // Setup history_isolation aka "history per session" - let history_isolation = config.history_isolation; + let history_isolation = engine_state.get_config().history_isolation; let history_session_id = if history_isolation { Reedline::create_history_session_id() } else { @@ -182,12 +174,8 @@ pub fn evaluate_repl( ); } - if engine_state.get_config().use_kitty_protocol { - if line_editor.can_use_kitty_protocol() { - line_editor.enable_kitty_protocol(); - } else { - warn!("Terminal doesn't support use_kitty_protocol config"); - } + if engine_state.get_config().use_kitty_protocol && !reedline::kitty_protocol_available() { + warn!("Terminal doesn't support use_kitty_protocol config"); } loop { @@ -261,6 +249,10 @@ pub fn evaluate_repl( start_time = std::time::Instant::now(); line_editor = line_editor + .use_kitty_keyboard_enhancement(config.use_kitty_protocol) + // try to enable bracketed paste + // It doesn't work on windows system: https://github.com/crossterm-rs/crossterm/issues/737 + .use_bracketed_paste(cfg!(not(target_os = "windows")) && config.bracketed_paste) .with_highlighter(Box::new(NuHighlighter { engine_state: engine_reference.clone(), config: config.clone(), @@ -590,10 +582,6 @@ pub fn evaluate_repl( PipelineData::empty(), false, ); - if engine_state.get_config().bracketed_paste { - #[cfg(not(target_os = "windows"))] - let _ = line_editor.enable_bracketed_paste(); - } } let cmd_duration = start_time.elapsed();