From d5aa9a797d640650f019c4e7dbc9e0a2229a29fa Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 6 Jul 2019 14:04:29 -0400 Subject: simplify --- src/repl.rs | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/repl.rs b/src/repl.rs index bde0b38..8bd3230 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -23,35 +23,37 @@ pub fn repl() { return None; } - let repl = read().and_then(|line| { - eval(&line).for_each(|event| { - futures::future::FutureResult::from(print(&event)) + let repl = read() + .and_then(|line| { + eval(&line).for_each(|event| { + futures::future::FutureResult::from(print(&event)) + }) }) - }); - Some(repl.then(|res| match res { - // successful run or empty input means prompt again - Ok(_) - | Err(Error::Eval { - source: - crate::eval::Error::Parser { - source: crate::parser::Error::CommandRequired, - .. - }, - }) => Ok((false, false)), - // eof means we're done - Err(Error::Read { - source: crate::readline::Error::EOF, - }) => Ok((false, true)), - // any other errors should be displayed, then we prompt again - Err(e) => { - let stderr = std::io::stderr(); - let mut stderr = stderr.lock(); - // panics seem fine for errors during error handling - write!(stderr, "{}\r\n", e).unwrap(); - stderr.flush().unwrap(); - Ok((false, false)) - } - })) + .then(|res| match res { + // successful run or empty input means prompt again + Ok(_) + | Err(Error::Eval { + source: + crate::eval::Error::Parser { + source: crate::parser::Error::CommandRequired, + .. + }, + }) => Ok((false, false)), + // eof means we're done + Err(Error::Read { + source: crate::readline::Error::EOF, + }) => Ok((false, true)), + // any other errors should be displayed, then we prompt again + Err(e) => { + let stderr = std::io::stderr(); + let mut stderr = stderr.lock(); + // panics seem fine for errors during error handling + write!(stderr, "{}\r\n", e).unwrap(); + stderr.flush().unwrap(); + Ok((false, false)) + } + }); + Some(repl) }); let loop_future = loop_stream.collect().map(|_| ()); tokio::run(loop_future); -- cgit v1.2.3-54-g00ecf