diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 10e049857e..573465ce8d 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -820,7 +820,9 @@ pub async fn cli( let cwd = context.shell_manager.path(); - rl.set_helper(Some(crate::shell::Helper::new(context.clone()))); + let hinter = init_hinter(&config); + + rl.set_helper(Some(crate::shell::Helper::new(context.clone(), hinter))); let colored_prompt = { if let Some(prompt) = config.get("prompt") { @@ -967,6 +969,18 @@ pub async fn cli( Ok(()) } +fn init_hinter(config: &IndexMap) -> Option { + // Show hints unless explicitly disabled in config + if let Some(line_editor_vars) = config.get("line_editor") { + for (idx, value) in line_editor_vars.row_entries() { + if idx == "show_hints" && value.expect_string() == "false" { + return None; + } + } + } + Some(rustyline::hint::HistoryHinter {}) +} + fn chomp_newline(s: &str) -> &str { if s.ends_with('\n') { &s[..s.len() - 1] diff --git a/crates/nu-cli/src/shell/helper.rs b/crates/nu-cli/src/shell/helper.rs index d0af32d8f7..af4f3bb58b 100644 --- a/crates/nu-cli/src/shell/helper.rs +++ b/crates/nu-cli/src/shell/helper.rs @@ -12,16 +12,16 @@ use crate::shell::palette::{DefaultPalette, Palette}; pub struct Helper { completer: NuCompleter, - hinter: rustyline::hint::HistoryHinter, + hinter: Option, context: Context, pub colored_prompt: String, } impl Helper { - pub(crate) fn new(context: Context) -> Helper { + pub(crate) fn new(context: Context, hinter: Option) -> Helper { Helper { completer: NuCompleter {}, - hinter: rustyline::hint::HistoryHinter {}, + hinter, context, colored_prompt: String::new(), } @@ -54,7 +54,7 @@ impl rustyline::completion::Completer for Helper { impl rustyline::hint::Hinter for Helper { fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option { - self.hinter.hint(line, pos, &ctx) + self.hinter.as_ref().and_then(|h| h.hint(line, pos, &ctx)) } }