mirror of
https://github.com/nushell/nushell.git
synced 2025-04-01 19:56:41 +02:00
allow esc and q to get out of completions
This commit is contained in:
parent
b7ad4dc78a
commit
c9439c962b
@ -1,6 +1,6 @@
|
|||||||
use std::{cell::RefCell, io::Write, rc::Rc};
|
use std::{cell::RefCell, io::Write, rc::Rc};
|
||||||
|
|
||||||
use dialoguer::{theme::ColorfulTheme, Select};
|
use dialoguer::{console::Term, theme::ColorfulTheme, Select};
|
||||||
use miette::{IntoDiagnostic, Result};
|
use miette::{IntoDiagnostic, Result};
|
||||||
use nu_cli::{report_error, NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
use nu_cli::{report_error, NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
||||||
use nu_command::create_default_context;
|
use nu_command::create_default_context;
|
||||||
@ -48,10 +48,12 @@ impl CompletionActionHandler for FuzzyCompletion {
|
|||||||
let result = Select::with_theme(&ColorfulTheme::default())
|
let result = Select::with_theme(&ColorfulTheme::default())
|
||||||
.default(0)
|
.default(0)
|
||||||
.items(&selections[..])
|
.items(&selections[..])
|
||||||
.interact()
|
.interact_on_opt(&Term::stdout())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let _ = crossterm::terminal::enable_raw_mode();
|
let _ = crossterm::terminal::enable_raw_mode();
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Some(result) => {
|
||||||
let span = completions[result].0;
|
let span = completions[result].0;
|
||||||
|
|
||||||
let mut offset = present_buffer.offset();
|
let mut offset = present_buffer.offset();
|
||||||
@ -61,6 +63,9 @@ impl CompletionActionHandler for FuzzyCompletion {
|
|||||||
present_buffer.replace(span.start..span.end, &completions[result].1);
|
present_buffer.replace(span.start..span.end, &completions[result].1);
|
||||||
present_buffer.set_insertion_point(offset);
|
present_buffer.set_insertion_point(offset);
|
||||||
}
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user