aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.rs13
-rw-r--r--src/input.rs6
-rw-r--r--src/main.rs37
3 files changed, 35 insertions, 21 deletions
diff --git a/src/app.rs b/src/app.rs
index eaaccc8..25002bd 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,8 +1,11 @@
use crate::input::{InputMode, InputParam, Row};
+pub const INPUT_TAB_INDEX: usize = 0;
+pub const CONFIG_TAB_INDEX: usize = 1;
+
pub struct App {
pub tab_index: usize,
- pub tab_titles: Vec<&'static str>,
+ tab_titles: [&'static str; 2],
pub rows: Vec<Row>,
pub selected_row: usize,
@@ -12,6 +15,10 @@ pub struct App {
}
impl App {
+ pub fn tab_titles(&self) -> &[&str] {
+ &self.tab_titles
+ }
+
pub fn next_tab(&mut self) {
self.tab_index = (self.tab_index + 1) % self.tab_titles.len();
}
@@ -66,8 +73,8 @@ impl App {
impl Default for App {
fn default() -> App {
App {
- tab_index: 0,
- tab_titles: vec!["Input", "Config"],
+ tab_index: INPUT_TAB_INDEX,
+ tab_titles: ["Input", "Config"],
rows: vec![Row::default()],
selected_row: 0,
selected_column: InputParam::Rpm(String::new()),
diff --git a/src/input.rs b/src/input.rs
index f6b1459..513aef6 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -11,6 +11,7 @@ pub enum InputParam {
Ve(String), // Volumetric efficiency
Map(String), // Manifold absolute pressure
}
+
impl InputParam {
/* Acts like the push() method of a Vec.
* Appends the given char to the end of the string contained by the
@@ -32,6 +33,7 @@ impl InputParam {
}
}
}
+
/* Acts like the pop() method of a Vec.
* Removes the last char from the string contained by the InputParam.
*/
@@ -51,6 +53,7 @@ impl InputParam {
}
}
}
+
// Return a copy of the string contained by the InputParam.
pub fn string(&self) -> String {
match self {
@@ -59,6 +62,7 @@ impl InputParam {
Self::Map(map) => map.to_string(),
}
}
+
/* next() and previous() allow InputParam to act as a circular iterator of
* sorts. next() will return the next variation as they are defined. When
* it reaches the end, the first variation will be returned:
@@ -73,6 +77,7 @@ impl InputParam {
Self::Map(_) => Self::Rpm(String::new()),
}
}
+
pub fn previous(&self) -> Self {
match self {
Self::Rpm(_) => Self::Map(String::new()),
@@ -89,6 +94,7 @@ pub struct Row {
pub ve: InputParam,
pub map: InputParam,
}
+
impl Default for Row {
fn default() -> Self {
Self {
diff --git a/src/main.rs b/src/main.rs
index 3ba8c0f..1fb4a39 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,7 @@ use tui::{
Frame, Terminal,
};
use volute::{
- app::App,
+ app::{App, CONFIG_TAB_INDEX, INPUT_TAB_INDEX},
input::{InputMode, InputParam},
};
@@ -52,8 +52,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
if let Event::Key(key) = event::read()? {
match app.tab_index {
- // Input tab
- 0 => match app.input_mode {
+ INPUT_TAB_INDEX => match app.input_mode {
InputMode::Normal => match key.code {
KeyCode::Char('q') => {
return Ok(());
@@ -88,8 +87,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
_ => {}
},
},
- // Config tab
- 1 => match key.code {
+ CONFIG_TAB_INDEX => match key.code {
KeyCode::Char('q') => {
return Ok(());
}
@@ -104,32 +102,35 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
}
fn ui<B: Backend>(f: &mut Frame<B>, app: &App) {
- let titles = app.tab_titles.iter().map(|t| Spans::from(*t)).collect();
+ let titles = app.tab_titles().iter().map(|t| Spans::from(*t)).collect();
let tabs = Tabs::new(titles)
.block(Block::default().borders(Borders::ALL).title("Tabs"))
.select(app.tab_index)
- .highlight_style(Style::default().add_modifier(Modifier::BOLD));
+ .highlight_style(
+ Style::default()
+ .fg(Color::Yellow)
+ .add_modifier(Modifier::BOLD),
+ );
match app.tab_index {
- // Input tab
- 0 => {
+ INPUT_TAB_INDEX => {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
- Constraint::Length(3),
- Constraint::Min(app.rows.len() as u16 + 2),
- Constraint::Length(1),
+ Constraint::Length(3), // Tabs
+ Constraint::Length(app.rows.len() as u16 + 3), // Input table
+ Constraint::Max(100), // Spacer
+ Constraint::Length(1), // Footer
]
.as_ref(),
)
.split(f.size());
f.render_widget(tabs, layout[0]);
f.render_widget(input_table(app), layout[1]);
- f.render_widget(footer(app), layout[2]);
+ f.render_widget(footer(app), layout[3]);
}
- // Config tab
- 1 => {
+ CONFIG_TAB_INDEX => {
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Min(3)].as_ref())
@@ -181,9 +182,9 @@ fn input_table(app: &App) -> impl Widget {
.header(widgets::Row::new(vec!["rpm", "ve", "map"]))
.block(Block::default().borders(Borders::ALL).title("inputs"))
.widths(&[
- Constraint::Length(5),
- Constraint::Length(3),
- Constraint::Length(3),
+ Constraint::Length(5), // rpm
+ Constraint::Length(3), // ve
+ Constraint::Length(3), // map
])
}