Handle EOF in repl mode
This commit is contained in:
parent
8d3354ec97
commit
51e5c0b80d
1 changed files with 11 additions and 4 deletions
15
src/main.rs
15
src/main.rs
|
@ -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();
|
||||||
run(line).unwrap();
|
if !line.is_empty() {
|
||||||
line_buf.clear();
|
run(line).unwrap();
|
||||||
|
line_buf.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => unimplemented!(),
|
Err(e) => panic!("{:?}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue