summaryrefslogtreecommitdiff
path: root/matrix-bin/src/repl.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-29 21:05:10 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-29 21:05:10 -0500
commitace046624d2e23fba67564a86af7f03ed8a48eae (patch)
tree21ae64bc5897b1b89ee2ab8563b0e7ce047bf34a /matrix-bin/src/repl.rs
parentfix readme (diff)
downloadmatrix-ace046624d2e23fba67564a86af7f03ed8a48eae.tar.gz
matrix-ace046624d2e23fba67564a86af7f03ed8a48eae.tar.bz2
matrix-ace046624d2e23fba67564a86af7f03ed8a48eae.zip
remove unwraps, fix utf8
Diffstat (limited to 'matrix-bin/src/repl.rs')
-rw-r--r--matrix-bin/src/repl.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/matrix-bin/src/repl.rs b/matrix-bin/src/repl.rs
index fe9975f..444faef 100644
--- a/matrix-bin/src/repl.rs
+++ b/matrix-bin/src/repl.rs
@@ -20,12 +20,12 @@ impl<'s, 'a> Repl<'s, 'a> {
Ok(val)
}
- pub fn run(&mut self) {
+ pub fn run(&mut self) -> Result<()> {
let interupt = self.state.vm.borrow().interupt();
ctrlc::set_handler(move || {
interupt.store(Interupt::KeyboardInterupt as usize, Ordering::SeqCst);
- }).unwrap();
+ }).exception()?;
let config = Config::builder()
.indent_size(4)
@@ -39,10 +39,10 @@ impl<'s, 'a> Repl<'s, 'a> {
let histfile = std::env::var("MATRIX_HISTORY").ok();
- let mut rl = Editor::with_config(config).unwrap();
+ let mut rl = Editor::with_config(config).exception()?;
rl.set_helper(Some(helper));
if let Some(hf) = &histfile {
- rl.load_history(hf).ok();
+ rl.load_history(hf).exception()?;
}
loop {
@@ -52,7 +52,7 @@ impl<'s, 'a> Repl<'s, 'a> {
Err(_) => continue,
};
- rl.add_history_entry(&line).ok();
+ rl.add_history_entry(&line).exception()?;
match self.execute(line) {
Ok(val) => {
@@ -66,12 +66,14 @@ impl<'s, 'a> Repl<'s, 'a> {
}
Err(err) => crate::error(err, &self.state),
};
- std::io::stdout().flush().ok();
+ std::io::stdout().flush().exception()?;
}
if let Some(hf) = &histfile {
- rl.save_history(hf).ok();
+ rl.save_history(hf).exception()?;
}
+
+ Ok(())
}
}