mirror of
https://github.com/nushell/nushell
synced 2025-01-15 14:44:14 +00:00
Add Support for Partial Completions (#3432)
This commit adds a conditional event handler that inserts the next word of the hint text when the user presses control and right arrow.
This commit is contained in:
parent
c0cc9ce7cd
commit
dc9cd7d8b9
4 changed files with 47 additions and 17 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -1686,6 +1686,16 @@ dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fd-lock"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0010f02effd88c702318c5dde0463206be67495d0b4d906ba7c0a8f166cc7f06"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filesize"
|
name = "filesize"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -1766,16 +1776,6 @@ dependencies = [
|
||||||
"percent-encoding 2.1.0",
|
"percent-encoding 2.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fs2"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"winapi 0.3.9",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fs_extra"
|
name = "fs_extra"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -5349,13 +5349,14 @@ checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustyline"
|
name = "rustyline"
|
||||||
version = "8.0.0"
|
version = "8.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/kkawakam/rustyline.git#795867591dc72c2be172af45aabd1c6ecd579225"
|
||||||
checksum = "b9e1b597fcd1eeb1d6b25b493538e5aa19629eb08932184b85fef931ba87e893"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
|
"clipboard-win",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
"fs2",
|
"error-code",
|
||||||
|
"fd-lock",
|
||||||
"libc",
|
"libc",
|
||||||
"log 0.4.14",
|
"log 0.4.14",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
|
@ -76,7 +76,7 @@ rayon = "1.5.0"
|
||||||
regex = "1.4.3"
|
regex = "1.4.3"
|
||||||
roxmltree = "0.14.0"
|
roxmltree = "0.14.0"
|
||||||
rust-embed = "5.9.0"
|
rust-embed = "5.9.0"
|
||||||
rustyline = { version = "8.0.0", optional = true }
|
rustyline = { git = "https://github.com/kkawakam/rustyline.git", optional = true }
|
||||||
serde = { version = "1.0.123", features = ["derive"] }
|
serde = { version = "1.0.123", features = ["derive"] }
|
||||||
serde_bytes = "0.11.5"
|
serde_bytes = "0.11.5"
|
||||||
serde_ini = "0.2.0"
|
serde_ini = "0.2.0"
|
||||||
|
|
|
@ -19,7 +19,8 @@ use rustyline::{
|
||||||
config::Configurer,
|
config::Configurer,
|
||||||
config::{ColorMode, CompletionType, Config},
|
config::{ColorMode, CompletionType, Config},
|
||||||
error::ReadlineError,
|
error::ReadlineError,
|
||||||
At, Cmd, Editor, Movement, Word,
|
line_buffer::LineBuffer,
|
||||||
|
At, Cmd, ConditionalEventHandler, Editor, EventHandler, Movement, Word,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "rustyline-support")]
|
#[cfg(feature = "rustyline-support")]
|
||||||
|
@ -36,6 +37,34 @@ pub fn convert_rustyline_result_to_string(input: Result<String, ReadlineError>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
#[cfg(feature = "rustyline-support")]
|
||||||
|
struct PartialCompleteHintHandler;
|
||||||
|
|
||||||
|
#[cfg(feature = "rustyline-support")]
|
||||||
|
impl ConditionalEventHandler for PartialCompleteHintHandler {
|
||||||
|
fn handle(
|
||||||
|
&self,
|
||||||
|
_evt: &rustyline::Event,
|
||||||
|
_n: rustyline::RepeatCount,
|
||||||
|
_positive: bool,
|
||||||
|
ctx: &rustyline::EventContext,
|
||||||
|
) -> Option<Cmd> {
|
||||||
|
Some(match ctx.hint_text() {
|
||||||
|
Some(hint_text) if ctx.pos() == ctx.line().len() => {
|
||||||
|
let mut line_buffer = LineBuffer::with_capacity(hint_text.len());
|
||||||
|
line_buffer.update(hint_text, 0);
|
||||||
|
line_buffer.move_to_next_word(At::AfterEnd, Word::Vi, 1);
|
||||||
|
|
||||||
|
let text = hint_text[0..line_buffer.pos()].to_string();
|
||||||
|
|
||||||
|
Cmd::Insert(1, text)
|
||||||
|
}
|
||||||
|
_ => Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rustyline-support")]
|
#[cfg(feature = "rustyline-support")]
|
||||||
pub fn default_rustyline_editor_configuration() -> Editor<Helper> {
|
pub fn default_rustyline_editor_configuration() -> Editor<Helper> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -56,7 +85,7 @@ pub fn default_rustyline_editor_configuration() -> Editor<Helper> {
|
||||||
);
|
);
|
||||||
rl.bind_sequence(
|
rl.bind_sequence(
|
||||||
convert_keyevent(KeyEvent::ControlRight),
|
convert_keyevent(KeyEvent::ControlRight),
|
||||||
Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)),
|
EventHandler::Conditional(Box::new(PartialCompleteHintHandler)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// workaround for multiline-paste hang in rustyline (see https://github.com/kkawakam/rustyline/issues/202)
|
// workaround for multiline-paste hang in rustyline (see https://github.com/kkawakam/rustyline/issues/202)
|
||||||
|
|
|
@ -74,7 +74,7 @@ rayon = "1.5.0"
|
||||||
regex = "1.4.3"
|
regex = "1.4.3"
|
||||||
roxmltree = "0.14.0"
|
roxmltree = "0.14.0"
|
||||||
rust-embed = "5.9.0"
|
rust-embed = "5.9.0"
|
||||||
rustyline = { version = "8.0.0", optional = true }
|
rustyline = { git = "https://github.com/kkawakam/rustyline.git", optional = true }
|
||||||
serde = { version = "1.0.123", features = ["derive"] }
|
serde = { version = "1.0.123", features = ["derive"] }
|
||||||
serde_bytes = "0.11.5"
|
serde_bytes = "0.11.5"
|
||||||
serde_ini = "0.2.0"
|
serde_ini = "0.2.0"
|
||||||
|
|
Loading…
Reference in a new issue