fixed val logic, added status

This commit is contained in:
Phani Pavan K
2025-10-20 11:55:32 +05:30
parent d713cc8fa3
commit 06a661b951
8 changed files with 129 additions and 52 deletions

View File

@@ -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(),
}