Newer
Older
use rustyline::error::ReadlineError;
use rustyline::{Config, CompletionType, Editor, EditMode};
// On unix platforms you can use ANSI escape sequences
#[cfg(unix)]
static PROMPT: &'static str = "\x1b[1;32m>>\x1b[0m ";
// Windows consoles typically don't support ANSI escape sequences out
// of the box
#[cfg(windows)]
static PROMPT: &'static str = ">> ";
let config = Config::builder()
.history_ignore_space(true)
let mut rl = Editor::with_config(config);
println!("No previous history.");
}
loop {
let readline = rl.readline(PROMPT);
match readline {
Ok(line) => {
println!("Line: {}", line);
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
Err(ReadlineError::Eof) => {
println!("CTRL-D");
Err(err) => {
println!("Error: {:?}", err);
}
}
rl.save_history("history.txt").unwrap();