commit | ffac1d199fd7f53eea5703196c6fbf021594a624 | [log] [tgz] |
---|---|---|
author | Gwenael Treguier <gwen@cas75-5-78-192-41-37.fbxo.proxad.net> | Mon Nov 16 18:49:50 2015 +0100 |
committer | Gwenael Treguier <gwen@cas75-5-78-192-41-37.fbxo.proxad.net> | Mon Nov 16 18:49:50 2015 +0100 |
tree | 3f85bcb798aaa12d4deb3497138a24d3fd589fc0 | |
parent | 345a7529147739695c02a686b4c92404afb130e9 [diff] |
Fix when stdin is not interactive (file or pipe).
Readline implementation in Rust that is based on Antirez' Linenoise
This project uses Cargo and Rust Nightly
cargo build --release
extern crate rustyline; use rustyline::error::ReadlineError; use rustyline::Editor; fn main() { let mut rl = Editor::new(); if let Err(_) = rl.load_history("history.txt") { println!("No previous history."); } loop { let readline = rl.readline(">> "); match readline { Ok(line) => { rl.add_history_entry(&line); println!("Line: {}", line); }, Err(ReadlineError::Interrupted) => { println!("CTRL-C"); break }, Err(ReadlineError::Eof) => { println!("CTRL-D"); break }, Err(err) => { println!("Error: {:?}", err); break } } } rl.save_history("history.txt").unwrap(); }
You can use this package in your project by adding the following to your Cargo.toml
:
[dependencies] rustyline = "0.1.0"