Improve history hinting (#551)

This commit is contained in:
JT 2021-12-22 20:12:24 +11:00 committed by GitHub
parent 8ba3e3570c
commit 9fb12fefb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 13 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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::<Vec<_>>();
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())