From d286ed3eb877365c01f7a7ec56de9a0dc84bab2e Mon Sep 17 00:00:00 2001 From: sam-anthony Date: Sun, 6 Mar 2022 21:56:57 -0330 Subject: simplify/remove a lot of stuff --- src/main.rs | 109 +++++++++++++----------------------------------------------- 1 file changed, 23 insertions(+), 86 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 207dde7..d3901da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,14 +7,9 @@ use std::{error::Error, io}; use tui::{ backend::{Backend, CrosstermBackend}, layout::{Constraint, Direction, Layout}, - widgets::Paragraph, Frame, Terminal, }; -use volute::{ - app::{App, Tab}, - input::InputMode, - ui, -}; +use volute::{app::App, ui}; fn main() -> Result<(), Box> { // setup terminal @@ -50,91 +45,33 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( terminal.draw(|f| ui(f, &app))?; if let Event::Key(key) = event::read()? { - match app.tab { - Tab::Const => match key.code { - KeyCode::Char('q') => { - return Ok(()); - } - KeyCode::Char('L') => app.next_tab(), - KeyCode::Char('H') => app.previous_tab(), - _ => {} - }, - Tab::Input => match app.input_mode { - InputMode::Normal => match key.code { - KeyCode::Char('q') => { - return Ok(()); - } - KeyCode::Char('L') => app.next_tab(), - KeyCode::Char('H') => app.previous_tab(), - KeyCode::Char('j') => app.next_row(), - KeyCode::Char('k') => app.previous_row(), - KeyCode::Char('l') => app.next_column(), - KeyCode::Char('h') => app.previous_column(), - KeyCode::Char('i') => { - app.input_mode = InputMode::Insert; - } - KeyCode::Char('p') => app.insert_row(), - KeyCode::Char('d') => app.remove_row(), - _ => {} - }, - InputMode::Insert => match key.code { - KeyCode::Esc | KeyCode::Enter => { - app.input_mode = InputMode::Normal; - } - KeyCode::Char(c) => { - if ('0'..'a').contains(&c) { - app.selected_input_param_mut().push(c); - } - } - KeyCode::Backspace => app.selected_input_param_mut().pop(), - _ => {} - }, - }, - Tab::Config => match key.code { - KeyCode::Char('q') => { - return Ok(()); + match key.code { + KeyCode::Char('q') => { + return Ok(()); + } + KeyCode::Char('j') => app.next_row(), + 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('d') => app.remove_row(), + KeyCode::Char(c) => { + if ('0'..'a').contains(&c) { + app.selected_input_param_mut().push(c); } - KeyCode::Char('L') => app.next_tab(), - KeyCode::Char('H') => app.previous_tab(), - _ => {} - }, + } + KeyCode::Backspace => app.selected_input_param_mut().pop(), + _ => {} } } } } fn ui(f: &mut Frame, app: &App) { - match app.tab { - Tab::Const => { - let layout = Layout::default() - .direction(Direction::Vertical) - .constraints(ui::constraints(app).as_ref()) - .split(f.size()); - f.render_widget(ui::tabs(app), layout[0]); - f.render_widget(Paragraph::new("Const Tab"), layout[1]); - } - Tab::Input => { - let layout = Layout::default() - .direction(Direction::Vertical) - .constraints(ui::constraints(app).as_ref()) - .split(f.size()); - f.render_widget(ui::tabs(app), layout[0]); - f.render_widget(ui::footer(app), layout[3]); - - let table_layout = Layout::default() - .direction(Direction::Horizontal) - .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) - .split(layout[1]); - f.render_widget(ui::input_table(app), table_layout[0]); - f.render_widget(ui::output_table(app), table_layout[1]); - } - Tab::Config => { - let layout = Layout::default() - .direction(Direction::Vertical) - .constraints(ui::constraints(app).as_ref()) - .split(f.size()); - f.render_widget(ui::tabs(app), layout[0]); - f.render_widget(Paragraph::new("Config tab"), layout[1]); - } - } + let layout = Layout::default() + .direction(Direction::Horizontal) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(f.size()); + f.render_widget(ui::input_table(app), layout[0]); + f.render_widget(ui::output_table(app), layout[1]); } -- cgit v1.2.3