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
This commit is contained in:
Stefan Holderbach 2023-11-14 20:27:14 +01:00 committed by GitHub
parent 942ff7df4d
commit 1b3092ae7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 20 deletions

2
Cargo.lock generated
View file

@ -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",

View file

@ -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();