Newer
Older
[](https://travis-ci.org/kkawakam/rustyline)
Readline implementation in Rust that is based on [Antirez' Linenoise](https://github.com/antirez/linenoise)
[Documentation](https://kkawakam.github.io/rustyline)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Example
``rust
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();
}
```
## crates.io
You can use this package in your project by adding the following
to your `Cargo.toml`:
``toml
[dependencies]
rustyline = "0.1.0"
```