aboutsummaryrefslogtreecommitdiffstats
path: root/src/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl.rs')
-rw-r--r--src/repl.rs38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/repl.rs b/src/repl.rs
index 3901e4c..8661022 100644
--- a/src/repl.rs
+++ b/src/repl.rs
@@ -6,13 +6,13 @@ use std::io::Write;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("error during read: {}", source))]
- ReadError { source: crate::readline::Error },
+ Read { source: crate::readline::Error },
#[snafu(display("error during eval: {}", source))]
- EvalError { source: crate::eval::Error },
+ Eval { source: crate::eval::Error },
#[snafu(display("error during print: {}", source))]
- PrintError { source: std::io::Error },
+ Print { source: std::io::Error },
}
pub type Result<T> = std::result::Result<T, Error>;
@@ -34,7 +34,7 @@ pub fn repl() {
futures::future::ok(Some(format!("{}", status)))
}
crate::eval::CommandEvent::BuiltinExit => {
- futures::future::ok(Some(format!("success")))
+ futures::future::ok(Some("success".to_string()))
}
})
});
@@ -42,33 +42,29 @@ pub fn repl() {
Some(repl.then(move |res| match res {
Ok(Some(status)) => {
eprint!("command exited: {}\r\n", status);
- return Ok((done, false));
+ Ok((done, false))
}
Ok(None) => {
eprint!("command exited weirdly?\r\n");
- return Ok((done, false));
+ Ok((done, false))
}
- Err(Error::ReadError {
+ Err(Error::Read {
source: crate::readline::Error::EOF,
- }) => {
- return Ok((done, true));
- }
- Err(Error::EvalError {
+ }) => Ok((done, true)),
+ Err(Error::Eval {
source:
- crate::eval::Error::ParserError {
+ crate::eval::Error::Parser {
source: crate::parser::Error::CommandRequired,
- line: _,
+ ..
},
- }) => {
- return Ok((done, false));
- }
+ }) => Ok((done, false)),
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();
- return Ok((done, false));
+ Ok((done, false))
}
}))
});
@@ -79,7 +75,7 @@ fn read() -> impl futures::future::Future<Item = String, Error = Error> {
crate::readline::readline("$ ", true)
.into_future()
.flatten()
- .map_err(|e| Error::ReadError { source: e })
+ .map_err(|e| Error::Read { source: e })
}
fn eval(
@@ -89,12 +85,12 @@ fn eval(
crate::eval::eval(line)
.into_future()
.flatten_stream()
- .map_err(|e| Error::EvalError { source: e })
+ .map_err(|e| Error::Eval { source: e })
}
fn print(out: &[u8]) -> Result<()> {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
- stdout.write(out).context(PrintError)?;
- stdout.flush().context(PrintError)
+ stdout.write(out).context(Print)?;
+ stdout.flush().context(Print)
}