aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-07-06 14:04:29 -0400
committerJesse Luehrs <doy@tozt.net>2019-07-06 14:04:29 -0400
commitd5aa9a797d640650f019c4e7dbc9e0a2229a29fa (patch)
treecf36f6aed45de6c1992ca159d22303a55ed7f0bb
parente66ca60da19754cae702c646f80c3ed7e5c6b5d8 (diff)
downloadnbsh-old-d5aa9a797d640650f019c4e7dbc9e0a2229a29fa.tar.gz
nbsh-old-d5aa9a797d640650f019c4e7dbc9e0a2229a29fa.zip
simplify
-rw-r--r--src/repl.rs58
1 files 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);