simple_repl/
simple_repl.rs1use editline::terminals::StdioTerminal;
4use editline::LineEditor;
5
6fn main() {
7 println!("Simple REPL - Type something and press Enter");
8 println!("Type 'exit' or press Ctrl-D to quit");
9 println!("Features: line editing, history (up/down), word navigation (Ctrl+arrows)");
10 println!("Press Ctrl-C to cancel current line");
11 println!();
12
13 let mut editor = LineEditor::new(1024, 50);
14 let mut terminal = StdioTerminal::new();
15
16 loop {
17 print!("> ");
18 std::io::Write::flush(&mut std::io::stdout()).unwrap();
19
20 match editor.read_line(&mut terminal) {
21 Ok(line) => {
22 if line == "exit" {
23 println!("Goodbye!");
24 break;
25 } else if !line.is_empty() {
26 println!("typed: {}", line);
27 }
28 }
29 Err(e) => {
30 match e {
32 editline::Error::Eof => {
33 println!("\nGoodbye!");
35 break;
36 }
37 editline::Error::Interrupted => {
38 println!("\nInterrupted. Type 'exit' or press Ctrl-D to quit.");
40 continue;
41 }
42 _ => {
43 eprintln!("\nError reading input: {}", e);
44 break;
45 }
46 }
47 }
48 }
49 }
50}