From d18b995228e44c88028412a11ede8c3d9982cae8 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Mon, 26 Apr 2021 18:11:23 -0400 Subject: [PATCH] Improve e handling --- src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8c59a0a..322ab03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -326,6 +326,14 @@ fn handle_key(app: &mut App, events: &Events, key: Key) { app.input.push(c); } Key::Char(c @ 'e') | Key::Char(c @ '.') => { + if app.input.is_empty() { + if let Ok(x) = app.calculator.pop() { + app.input = x.to_string(); + } else { + return; + } + } + if !app.input.contains(c) { app.input.push(c); } @@ -333,9 +341,16 @@ fn handle_key(app: &mut App, events: &Events, key: Key) { Key::Char('\n') | Key::Char(' ') => { if app.input.is_empty() { calc_operation(app, '\n'); - } else if let Ok(f) = app.input.parse::() { - if app.calculator.push(f).is_ok() { - app.input.clear(); + } else { + let mut tmp_input = app.input.clone(); + if tmp_input.ends_with('e') { + let tmp_input = tmp_input.push('0'); + } + + if let Ok(f) = tmp_input.parse::() { + if app.calculator.push(f).is_ok() { + app.input.clear(); + } } } }