Set cancel return type to result
This commit is contained in:
parent
d81fb1f45d
commit
062cd97609
11
src/calc.rs
11
src/calc.rs
@ -205,7 +205,8 @@ impl<'a> Calculator<'a> {
|
||||
|
||||
for c in value.chars() {
|
||||
self.take_input(c).map_err(|e| {
|
||||
self.cancel();
|
||||
// Try cancelling, but if you cannot, that is okay
|
||||
self.cancel().unwrap_or(());
|
||||
e
|
||||
})?;
|
||||
}
|
||||
@ -239,9 +240,15 @@ impl<'a> Calculator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel(&mut self) {
|
||||
pub fn cancel(&mut self) -> CalculatorResult<()> {
|
||||
self.state = CalculatorState::Normal;
|
||||
// We died in a macro. Quit and push an end macro state
|
||||
if !self.active_macros.is_empty() {
|
||||
self.active_macros.clear();
|
||||
// Should always be successful, but report the error if there is one
|
||||
self.op(CalculatorOperation::Macro(MacroState::End))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn backspace(&mut self) -> CalculatorResult<()> {
|
||||
self.l.pop();
|
||||
|
@ -268,7 +268,7 @@ fn handle_key(app: &mut App, events: &Events, key: Key) -> CalculatorResult<bool
|
||||
(AppState::Help, _) => match key {
|
||||
Key::Esc | Key::Char('q') => {
|
||||
app.state = AppState::Calculator;
|
||||
app.calculator.cancel();
|
||||
app.calculator.cancel()?;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@ -277,7 +277,7 @@ fn handle_key(app: &mut App, events: &Events, key: Key) -> CalculatorResult<bool
|
||||
| (AppState::Calculator, CalculatorState::WaitingForMacro) => match key {
|
||||
Key::Esc => {
|
||||
app.state = AppState::Calculator;
|
||||
app.calculator.cancel();
|
||||
app.calculator.cancel()?;
|
||||
}
|
||||
Key::Char(c) => {
|
||||
app.calculator.take_input(c)?;
|
||||
|
Loading…
Reference in New Issue
Block a user