Help menu improvements (#4997)

* Help menu improvements

* default config
This commit is contained in:
JT 2022-03-28 09:21:40 +13:00 committed by GitHub
parent 2873e943b3
commit 911fba8a8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View File

@ -1,5 +1,5 @@
use nu_engine::documentation::get_flags_section;
use nu_protocol::engine::EngineState;
use nu_protocol::{engine::EngineState, levenshtein_distance};
use reedline::{Completer, Suggestion};
pub const EXAMPLE_MARKER: &str = ">>>>>>";
@ -18,7 +18,7 @@ impl NuHelpCompleter {
let full_commands = self.engine_state.get_signatures_with_examples(false);
//Vec<(Signature, Vec<Example>, bool, bool)> {
full_commands
let mut commands = full_commands
.iter()
.filter(|(sig, _, _, _)| {
sig.name.to_lowercase().contains(&line.to_lowercase())
@ -28,6 +28,16 @@ impl NuHelpCompleter {
.to_lowercase()
.contains(&line.to_lowercase())
})
.collect::<Vec<_>>();
commands.sort_by(|(a, _, _, _), (b, _, _, _)| {
let a_distance = levenshtein_distance(line, &a.name);
let b_distance = levenshtein_distance(line, &b.name);
a_distance.cmp(&b_distance)
});
commands
.into_iter()
.map(|(sig, examples, _, _)| {
let mut long_desc = String::new();

View File

@ -93,7 +93,7 @@ impl Default for NuHelpMenu {
values: Vec::new(),
col_pos: 0,
row_pos: 0,
marker: "| ".to_string(),
marker: "? ".to_string(),
event: None,
input: None,
examples: Vec::new(),

View File

@ -222,7 +222,7 @@ fn add_menu_keybindings(keybindings: &mut Keybindings) {
KeyModifiers::NONE,
KeyCode::Tab,
ReedlineEvent::UntilFound(vec![
ReedlineEvent::Menu("completer_menu".to_string()),
ReedlineEvent::Menu("completion_menu".to_string()),
ReedlineEvent::MenuNext,
]),
);
@ -255,7 +255,7 @@ fn add_menu_keybindings(keybindings: &mut Keybindings) {
// Help menu keybinding
keybindings.add_binding(
KeyModifiers::CONTROL,
KeyCode::Char('i'),
KeyCode::Char('q'),
ReedlineEvent::Menu("help_menu".to_string()),
);
}

View File

@ -221,7 +221,7 @@ let $config = {
text_style: green
selected_text_style: green_reverse
description_text_style: yellow
marker: "% "
marker: "? "
}
keybindings: [
{