Handle EOF in repl mode

This commit is contained in:
bad 2022-04-02 21:36:06 +02:00
parent 8d3354ec97
commit 51e5c0b80d

View file

@ -19,12 +19,19 @@ fn run_repl() {
let mut line_buf = String::new(); let mut line_buf = String::new();
loop { loop {
match io::stdin().read_line(&mut line_buf) { match io::stdin().read_line(&mut line_buf) {
Ok(_) => { Ok(n) => {
// Check for EOF
if n == 0 {
break;
}
let line = line_buf.trim(); let line = line_buf.trim();
if !line.is_empty() {
run(line).unwrap(); run(line).unwrap();
line_buf.clear(); line_buf.clear();
} }
Err(_e) => unimplemented!(), }
Err(e) => panic!("{:?}", e),
} }
} }
} }