From 51e5c0b80df3108b721f148db968ed484a83e6f5 Mon Sep 17 00:00:00 2001 From: bad Date: Sat, 2 Apr 2022 21:36:06 +0200 Subject: [PATCH] Handle EOF in repl mode --- src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 045b5d8..1b25094 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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), } } }