From ace046624d2e23fba67564a86af7f03ed8a48eae Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 29 Feb 2024 21:05:10 -0500 Subject: remove unwraps, fix utf8 --- matrix-bin/src/repl.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'matrix-bin/src/repl.rs') 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(()) } } -- cgit v1.2.3-freya