Skip to content

Commit

Permalink
Move to clearer reedline keyboard enhancement API (#11045)
Browse files Browse the repository at this point in the history
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 nushell/reedline#659
(pointing to personal fork)

Closes #10982
Supersedes #10998
  • Loading branch information
sholderbach committed Nov 14, 2023
1 parent 942ff7d commit 1b3092a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 7 additions & 19 deletions crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 1b3092a

Please sign in to comment.