Handle EOF in repl mode

This commit is contained in:
bad 2022-04-02 21:36:06 +02:00
parent 8d3354ec97
commit 51e5c0b80d
1 changed files with 11 additions and 4 deletions

View File

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