forked from extern/nushell
remove dialoguer completions in favor of reedline's (#766)
This commit is contained in:
parent
085a7c18cb
commit
ac36f32647
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -856,7 +856,6 @@ dependencies = [
|
||||
"crossterm",
|
||||
"crossterm_winapi",
|
||||
"ctrlc",
|
||||
"dialoguer",
|
||||
"log",
|
||||
"miette",
|
||||
"nu-ansi-term",
|
||||
@ -4021,9 +4020,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.4.3"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619"
|
||||
checksum = "cc222aec311c323c717f56060324f32b82da1ce1dd81d9a09aa6a9030bfe08db"
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
|
@ -23,7 +23,6 @@ members = [
|
||||
[dependencies]
|
||||
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
|
||||
crossterm = "0.22.*"
|
||||
dialoguer = "0.9.0"
|
||||
nu-cli = { path="./crates/nu-cli" }
|
||||
nu-command = { path="./crates/nu-command" }
|
||||
nu-engine = { path="./crates/nu-engine" }
|
||||
@ -36,7 +35,6 @@ nu-plugin = { path = "./crates/nu-plugin", optional = true }
|
||||
nu-system = { path = "./crates/nu-system"}
|
||||
nu-table = { path = "./crates/nu-table" }
|
||||
nu-term-grid = { path = "./crates/nu-term-grid" }
|
||||
# nu-ansi-term = { path = "./crates/nu-ansi-term" }
|
||||
nu-ansi-term = "0.42.0"
|
||||
nu-color-config = { path = "./crates/nu-color-config" }
|
||||
miette = "3.0.0"
|
||||
|
66
src/main.rs
66
src/main.rs
@ -1,11 +1,6 @@
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
#[cfg(windows)]
|
||||
use crossterm_winapi::{ConsoleMode, Handle};
|
||||
use dialoguer::{
|
||||
console::{Style, Term},
|
||||
theme::ColorfulTheme,
|
||||
Select,
|
||||
};
|
||||
use log::trace;
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use nu_cli::{CliError, NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
||||
@ -19,8 +14,8 @@ use nu_protocol::{
|
||||
Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
|
||||
};
|
||||
use reedline::{
|
||||
default_emacs_keybindings, Completer, CompletionActionHandler, ContextMenuInput, DefaultHinter,
|
||||
EditCommand, Emacs, LineBuffer, Prompt, ReedlineEvent, Vi,
|
||||
default_emacs_keybindings, ContextMenuInput, DefaultHinter, EditCommand, Emacs, Prompt,
|
||||
ReedlineEvent, Vi,
|
||||
};
|
||||
use std::{
|
||||
io::Write,
|
||||
@ -44,57 +39,6 @@ const PROMPT_INDICATOR_VI_INSERT: &str = "PROMPT_INDICATOR_VI_INSERT";
|
||||
const PROMPT_INDICATOR_VI_VISUAL: &str = "PROMPT_INDICATOR_VI_VISUAL";
|
||||
const PROMPT_MULTILINE_INDICATOR: &str = "PROMPT_MULTILINE_INDICATOR";
|
||||
|
||||
struct FuzzyCompletion {
|
||||
completer: Box<dyn Completer>,
|
||||
}
|
||||
|
||||
impl CompletionActionHandler for FuzzyCompletion {
|
||||
fn handle(&mut self, present_buffer: &mut LineBuffer) {
|
||||
let completions = self
|
||||
.completer
|
||||
.complete(present_buffer.get_buffer(), present_buffer.offset());
|
||||
|
||||
if completions.is_empty() {
|
||||
// do nothing
|
||||
} else if completions.len() == 1 {
|
||||
let span = completions[0].0;
|
||||
|
||||
let mut offset = present_buffer.offset();
|
||||
offset += completions[0].1.len() - (span.end - span.start);
|
||||
|
||||
// TODO improve the support for multiline replace
|
||||
present_buffer.replace(span.start..span.end, &completions[0].1);
|
||||
present_buffer.set_insertion_point(offset);
|
||||
} else {
|
||||
let selections: Vec<_> = completions.iter().map(|(_, string)| string).collect();
|
||||
|
||||
let _ = crossterm::terminal::disable_raw_mode();
|
||||
println!();
|
||||
let theme = ColorfulTheme {
|
||||
active_item_style: Style::new().for_stderr().on_green().black(),
|
||||
..Default::default()
|
||||
};
|
||||
let result = Select::with_theme(&theme)
|
||||
.default(0)
|
||||
.items(&selections[..])
|
||||
.interact_on_opt(&Term::stdout())
|
||||
.unwrap_or(None);
|
||||
let _ = crossterm::terminal::enable_raw_mode();
|
||||
|
||||
if let Some(result) = result {
|
||||
let span = completions[result].0;
|
||||
|
||||
let mut offset = present_buffer.offset();
|
||||
offset += completions[result].1.len() - (span.end - span.start);
|
||||
|
||||
// TODO improve the support for multiline replace
|
||||
present_buffer.replace(span.start..span.end, &completions[result].1);
|
||||
present_buffer.set_insertion_point(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// miette::set_panic_hook();
|
||||
let miette_hook = std::panic::take_hook();
|
||||
@ -419,12 +363,6 @@ fn main() -> Result<()> {
|
||||
|
||||
let line_editor = Reedline::create()
|
||||
.into_diagnostic()?
|
||||
// .with_completion_action_handler(Box::new(FuzzyCompletion {
|
||||
// completer: Box::new(NuCompleter::new(engine_state.clone())),
|
||||
// }))
|
||||
// .with_completion_action_handler(Box::new(
|
||||
// ListCompletionHandler::default().with_completer(Box::new(completer)),
|
||||
// ))
|
||||
.with_highlighter(Box::new(NuHighlighter {
|
||||
engine_state: engine_state.clone(),
|
||||
config: config.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user