mirror of
https://github.com/nushell/reedline.git
synced 2024-11-13 08:50:55 +03:00
835d2e9f25
Puts the minimal examples from the documentation as separate example executables to play around with
32 lines
935 B
Rust
32 lines
935 B
Rust
// Create a reedline object with in-line hint support.
|
|
// cargo run --example hinter
|
|
//
|
|
// Fish-style history based hinting.
|
|
// assuming history ["abc", "ade"]
|
|
// pressing "a" hints to abc.
|
|
// Up/Down or Ctrl p/n, to select next/previous match
|
|
|
|
use nu_ansi_term::{Color, Style};
|
|
use reedline::{DefaultHinter, DefaultPrompt, Reedline, Signal};
|
|
use std::io;
|
|
|
|
fn main() -> io::Result<()> {
|
|
let mut line_editor = Reedline::create().with_hinter(Box::new(
|
|
DefaultHinter::default().with_style(Style::new().italic().fg(Color::LightGray)),
|
|
));
|
|
let prompt = DefaultPrompt::default();
|
|
|
|
loop {
|
|
let sig = line_editor.read_line(&prompt)?;
|
|
match sig {
|
|
Signal::Success(buffer) => {
|
|
println!("We processed: {}", buffer);
|
|
}
|
|
Signal::CtrlD | Signal::CtrlC => {
|
|
println!("\nAborted!");
|
|
break Ok(());
|
|
}
|
|
}
|
|
}
|
|
}
|