aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorsam-anthony <samanthony6@protonmail.com>2022-03-08 19:55:08 -0330
committersam-anthony <samanthony6@protonmail.com>2022-03-08 19:55:08 -0330
commit90f42ad66feb6b77474d0da267d572eca16e2826 (patch)
treea35319f2457e2e65bf8ff4536e142b7211fb09b9 /src/main.rs
parentd286ed3eb877365c01f7a7ec56de9a0dc84bab2e (diff)
downloadvolute-90f42ad66feb6b77474d0da267d572eca16e2826.zip
switchable pressure unit
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index d3901da..60b1fed 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,7 +9,12 @@ use tui::{
layout::{Constraint, Direction, Layout},
Frame, Terminal,
};
-use volute::{app::App, ui};
+use volute::{
+ app::App,
+ input::InputParam,
+ ui,
+ unit_of_measurement::{pressure::Pressure, UnitOfMeasurement},
+};
fn main() -> Result<(), Box<dyn Error>> {
// setup terminal
@@ -53,14 +58,45 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
KeyCode::Char('k') => app.previous_row(),
KeyCode::Char('l') => app.next_column(),
KeyCode::Char('h') => app.previous_column(),
- KeyCode::Char('p') => app.insert_row(),
+ KeyCode::Char('y') => app.insert_row(),
KeyCode::Char('d') => app.remove_row(),
+ KeyCode::Char('p') => app.pressure_unit.next(),
KeyCode::Char(c) => {
- if ('0'..'a').contains(&c) {
- app.selected_input_param_mut().push(c);
+ if ('0'..':').contains(&c) {
+ // 0 to 9 inclusive
+ let digit = c.to_digit(10).unwrap();
+ match app.selected_input_param() {
+ InputParam::Rpm(rpm) => {
+ *app.selected_input_param_mut() =
+ InputParam::Rpm(*rpm * 10 + digit);
+ }
+ InputParam::Ve(ve) => {
+ *app.selected_input_param_mut() = InputParam::Ve(*ve * 10 + digit);
+ }
+ InputParam::Map(p) => {
+ *app.selected_input_param_mut() =
+ InputParam::Map(Pressure::from_unit(
+ app.pressure_unit,
+ p.as_unit(app.pressure_unit) * 10 + digit as i32,
+ ))
+ }
+ }
}
}
- KeyCode::Backspace => app.selected_input_param_mut().pop(),
+ KeyCode::Backspace => match app.selected_input_param() {
+ InputParam::Rpm(rpm) => {
+ *app.selected_input_param_mut() = InputParam::Rpm(*rpm / 10);
+ }
+ InputParam::Ve(ve) => {
+ *app.selected_input_param_mut() = InputParam::Ve(*ve / 10);
+ }
+ InputParam::Map(p) => {
+ *app.selected_input_param_mut() = InputParam::Map(Pressure::from_unit(
+ app.pressure_unit,
+ p.as_unit(app.pressure_unit) / 10,
+ ))
+ }
+ },
_ => {}
}
}