fixed val logic, added status
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -16,7 +16,9 @@ use ratatui::crossterm::terminal::{
|
||||
use ratatui::prelude::{Backend, CrosstermBackend};
|
||||
use std::io;
|
||||
|
||||
use crate::app::status::{CurrentScreen, EditingField};
|
||||
use crate::app::status::{
|
||||
AppStatus, CurrentScreen, EditingField, EntryValError, entryValError2Field,
|
||||
};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
enable_raw_mode()?;
|
||||
@@ -64,8 +66,8 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
|
||||
_ => {}
|
||||
},
|
||||
CurrentScreen::Delete => match key.code {
|
||||
KeyCode::Up => app.nextRow(),
|
||||
KeyCode::Down => app.prevRow(),
|
||||
KeyCode::Up => app.prevRow(),
|
||||
KeyCode::Down => app.nextRow(),
|
||||
KeyCode::Enter => app.delCur(),
|
||||
KeyCode::Esc => app.screen = CurrentScreen::Main,
|
||||
_ => {}
|
||||
@@ -74,14 +76,15 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
|
||||
KeyCode::Char('a') => {
|
||||
app.screen = CurrentScreen::Add;
|
||||
app.currentlyEditing = Some(EditingField::FromIP);
|
||||
app.appStatus = AppStatus::Editing;
|
||||
}
|
||||
KeyCode::Char('q') | KeyCode::F(10) | KeyCode::Esc => {
|
||||
app.screen = CurrentScreen::Exit
|
||||
}
|
||||
KeyCode::Char('s') | KeyCode::F(2) => app.screen = CurrentScreen::Settings,
|
||||
KeyCode::Char('d') => app.screen = CurrentScreen::Delete,
|
||||
KeyCode::Up => app.nextRow(),
|
||||
KeyCode::Down => app.prevRow(),
|
||||
KeyCode::Up => app.prevRow(),
|
||||
KeyCode::Down => app.nextRow(),
|
||||
_ => {}
|
||||
},
|
||||
CurrentScreen::Add => match (key.modifiers, key.code) {
|
||||
@@ -89,9 +92,18 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
|
||||
if let Some(eF) = &app.currentlyEditing {
|
||||
match eF {
|
||||
EditingField::ToPort => {
|
||||
app.store();
|
||||
app.screen = CurrentScreen::Main;
|
||||
app.currentlyEditing = None;
|
||||
let res = app.store();
|
||||
match res {
|
||||
EntryValError::NONE => {
|
||||
app.screen = CurrentScreen::Main;
|
||||
app.currentlyEditing = None;
|
||||
app.appStatus = AppStatus::Added;
|
||||
}
|
||||
_ => {
|
||||
app.currentlyEditing = Some(entryValError2Field(&res));
|
||||
app.appStatus = AppStatus::Error(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => app.nextField(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user