-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlinenoise_example.rs
43 lines (39 loc) · 1018 Bytes
/
linenoise_example.rs
1
2
3
4
5
6
7
8
9
10
11
12
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
extern crate linenoise;
fn callback(input: &str) -> Vec<String> {
let ret : Vec<&str>;
if input.starts_with("s") {
ret = vec!["suggestion", "suggestion2", "suggestion-three"];
} else {
ret = vec!["wot"];
}
return ret.iter().map(|s| s.to_string()).collect();
}
fn main() {
linenoise::set_callback(callback);
linenoise::set_multiline(0);
loop {
let val = linenoise::input("Hello Dave -> ");
match val {
None => { break }
Some(input) => {
println!("> {}", input);
linenoise::history_add(input.as_ref());
let is: &str = input.as_ref();
if is == "clear" {
linenoise::clear_screen();
} else if is == "history" {
let mut index = 0;
loop {
match linenoise::history_line(index) {
None => { break; },
Some(line) => {
println!("{}: {}", index, line);
}
};
index = index + 1;
}
}
}
}
}
}