mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Improve history hinting (#551)
This commit is contained in:
parent
8ba3e3570c
commit
9fb12fefb0
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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",
|
||||
|
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())
|
||||
|
Loading…
Reference in New Issue
Block a user