diff --git a/src/main.rs b/src/main.rs index db1fbc5..abf4cf6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,11 @@ struct App { current_macro: Option, } +enum CalculatorResponse { + Quit, + Continue, +} + impl Default for App { fn default() -> Self { let (calculator, error_msg) = match Calculator::load_config() { @@ -263,8 +268,8 @@ fn main() -> Result<(), Box> { if let Event::Input(key) = events.next()? { app.error_msg = match handle_key(&mut app, &events, key) { // Exit the program - Ok(true) => break 'outer Ok(()), - Ok(false) => None, + Ok(CalculatorResponse::Quit) => break 'outer Ok(()), + Ok(CalculatorResponse::Continue) => None, Err(e) => Some(format!("{}", e)), }; } @@ -274,8 +279,8 @@ fn main() -> Result<(), Box> { Event::Input(key) => { app.error_msg = match handle_key(&mut app, &events, key) { // Exit the program - Ok(true) => break 'outer Ok(()), - Ok(false) => None, + Ok(CalculatorResponse::Quit) => break 'outer Ok(()), + Ok(CalculatorResponse::Continue) => None, Err(e) => Some(format!("{}", e)), }; } @@ -288,11 +293,11 @@ fn main() -> Result<(), Box> { } } -fn handle_key(app: &mut App, events: &Events, key: Key) -> CalculatorResult { +fn handle_key(app: &mut App, events: &Events, key: Key) -> CalculatorResult { match (&app.state, app.calculator.get_state()) { (AppState::Calculator, CalculatorState::Normal) => match key { Key::Char('q') => { - return Ok(true); + return Ok(CalculatorResponse::Quit); } Key::Ctrl('s') => { app.calculator.save_config()?; @@ -341,7 +346,7 @@ fn handle_key(app: &mut App, events: &Events, key: Key) -> CalculatorResult {} }, } - Ok(false) + Ok(CalculatorResponse::Continue) } struct ClippyRectangle<'a> {