From 911fba8a8a9eb7b14ceaddaecf4a5fc5787b10ae Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Mon, 28 Mar 2022 09:21:40 +1300 Subject: [PATCH] Help menu improvements (#4997) * Help menu improvements * default config --- crates/nu-cli/src/help_completions.rs | 14 ++++++++++++-- crates/nu-cli/src/help_menu.rs | 2 +- crates/nu-cli/src/reedline_config.rs | 4 ++-- docs/sample_config/default_config.nu | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/nu-cli/src/help_completions.rs b/crates/nu-cli/src/help_completions.rs index 12d336d57..f385cad24 100644 --- a/crates/nu-cli/src/help_completions.rs +++ b/crates/nu-cli/src/help_completions.rs @@ -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, 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::>(); + + 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(); diff --git a/crates/nu-cli/src/help_menu.rs b/crates/nu-cli/src/help_menu.rs index c8b9ae47d..a36e54397 100644 --- a/crates/nu-cli/src/help_menu.rs +++ b/crates/nu-cli/src/help_menu.rs @@ -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(), diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index 8c2405513..20cc6e88e 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -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()), ); } diff --git a/docs/sample_config/default_config.nu b/docs/sample_config/default_config.nu index e96099c4a..8cc335450 100644 --- a/docs/sample_config/default_config.nu +++ b/docs/sample_config/default_config.nu @@ -221,7 +221,7 @@ let $config = { text_style: green selected_text_style: green_reverse description_text_style: yellow - marker: "% " + marker: "? " } keybindings: [ {