Commit | Line | Data |
---|---|---|
4ef4b17c JM |
1 | #[macro_use] |
2 | extern crate lazy_static; | |
4ef4b17c | 3 | extern crate fnv; |
4a649b37 RF |
4 | extern crate itertools; |
5 | extern crate regex; | |
4ef4b17c JM |
6 | |
7 | extern crate rustyline; | |
8 | use rustyline::error::ReadlineError; | |
9 | use rustyline::Editor; | |
10 | ||
11 | #[macro_use] | |
12 | #[allow(dead_code)] | |
13 | mod types; | |
c9b18677 | 14 | use crate::types::format_error; |
4ef4b17c | 15 | mod printer; |
4a649b37 | 16 | mod reader; |
4ef4b17c JM |
17 | // TODO: figure out a way to avoid including env |
18 | #[allow(dead_code)] | |
19 | mod env; | |
20 | ||
21 | fn main() { | |
4a649b37 RF |
22 | // `()` can be used when no completer is required |
23 | let mut rl = Editor::<()>::new(); | |
24 | if rl.load_history(".mal-history").is_err() { | |
25 | eprintln!("No previous history."); | |
26 | } | |
4ef4b17c | 27 | |
4a649b37 RF |
28 | loop { |
29 | let readline = rl.readline("user> "); | |
30 | match readline { | |
31 | Ok(line) => { | |
32 | rl.add_history_entry(&line); | |
33 | rl.save_history(".mal-history").unwrap(); | |
34 | if line.len() > 0 { | |
35 | match reader::read_str(line) { | |
36 | Ok(mv) => { | |
37 | println!("{}", mv.pr_str(true)); | |
38 | } | |
39 | Err(e) => println!("Error: {}", format_error(e)), | |
40 | } | |
41 | } | |
42 | } | |
43 | Err(ReadlineError::Interrupted) => continue, | |
44 | Err(ReadlineError::Eof) => break, | |
45 | Err(err) => { | |
46 | println!("Error: {:?}", err); | |
47 | break; | |
48 | } | |
4ef4b17c | 49 | } |
4ef4b17c | 50 | } |
4ef4b17c | 51 | } |