mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 15:11:52 +02:00
Improve history hinting (#551)
This commit is contained in:
17
src/main.rs
17
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::<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())
|
||||
|
Reference in New Issue
Block a user