aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
index cc93415..ecb4b3f 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -15,6 +15,9 @@ impl Calculator {
KeyCode::Char('q') => {
return Signal::Exit;
}
+ KeyCode::Char('j' | 'k') => {
+ self.swap();
+ }
KeyCode::Char(c) => {
self.push_to_buffer(c);
}
@@ -51,4 +54,13 @@ impl Calculator {
self.stack.push(self.input_buffer.parse::<f64>().unwrap());
self.input_buffer = String::new();
}
+
+ fn swap(&mut self) {
+ if let Some(f) = self.stack.pop() {
+ if self.input_buffer.len() > 0 {
+ self.push_buffer_to_stack();
+ }
+ self.input_buffer = format!("{}", f);
+ }
+ }
}