From 9fb12fefb00b354d408d1095f82ddd6be682ae3a Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Wed, 22 Dec 2021 20:12:24 +1100 Subject: [PATCH] Improve history hinting (#551) --- Cargo.lock | 2 +- src/main.rs | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1432dc1a5..2d542c3ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2535,7 +2535,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.2.0" -source = "git+https://github.com/nushell/reedline?branch=main#e512512dd4af9f3aad19c0f045f03b0b1680eb99" +source = "git+https://github.com/nushell/reedline?branch=main#c810d65a9d9440e706fcc6c91a32707f0c526f8d" dependencies = [ "chrono", "crossterm", diff --git a/src/main.rs b/src/main.rs index 3f288f653..efe6bd433 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,7 @@ use nu_protocol::{ Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID, }; use reedline::{ - Completer, CompletionActionHandler, DefaultCompleter, DefaultHinter, DefaultPrompt, LineBuffer, - Prompt, + Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt, }; use std::{ io::Write, @@ -357,18 +356,12 @@ fn main() -> Result<()> { let mut line_editor = if let Some(history_path) = history_path.clone() { let history = std::fs::read_to_string(&history_path); - if let Ok(history) = history { - let history_lines = history.lines().map(|x| x.to_string()).collect::>(); + if history.is_ok() { line_editor .with_hinter(Box::new( - DefaultHinter::default() - .with_completer(Box::new(DefaultCompleter::new(history_lines))) // or .with_history() - // .with_inside_line() - .with_style( - nu_ansi_term::Style::new() - .italic() - .fg(nu_ansi_term::Color::LightGray), - ), + DefaultHinter::default().with_history().with_style( + nu_ansi_term::Style::new().fg(nu_ansi_term::Color::DarkGray), + ), )) .with_history(Box::new( FileBackedHistory::with_file(1000, history_path.clone())