forked from extern/nushell
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]]
|
[[package]]
|
||||||
name = "reedline"
|
name = "reedline"
|
||||||
version = "0.2.0"
|
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 = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -16,8 +16,7 @@ use nu_protocol::{
|
|||||||
Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
|
Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
|
||||||
};
|
};
|
||||||
use reedline::{
|
use reedline::{
|
||||||
Completer, CompletionActionHandler, DefaultCompleter, DefaultHinter, DefaultPrompt, LineBuffer,
|
Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt,
|
||||||
Prompt,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
io::Write,
|
io::Write,
|
||||||
@ -357,17 +356,11 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let mut line_editor = if let Some(history_path) = history_path.clone() {
|
let mut line_editor = if let Some(history_path) = history_path.clone() {
|
||||||
let history = std::fs::read_to_string(&history_path);
|
let history = std::fs::read_to_string(&history_path);
|
||||||
if let Ok(history) = history {
|
if history.is_ok() {
|
||||||
let history_lines = history.lines().map(|x| x.to_string()).collect::<Vec<_>>();
|
|
||||||
line_editor
|
line_editor
|
||||||
.with_hinter(Box::new(
|
.with_hinter(Box::new(
|
||||||
DefaultHinter::default()
|
DefaultHinter::default().with_history().with_style(
|
||||||
.with_completer(Box::new(DefaultCompleter::new(history_lines))) // or .with_history()
|
nu_ansi_term::Style::new().fg(nu_ansi_term::Color::DarkGray),
|
||||||
// .with_inside_line()
|
|
||||||
.with_style(
|
|
||||||
nu_ansi_term::Style::new()
|
|
||||||
.italic()
|
|
||||||
.fg(nu_ansi_term::Color::LightGray),
|
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
.with_history(Box::new(
|
.with_history(Box::new(
|
||||||
|
Loading…
Reference in New Issue
Block a user