added colours, select and delete ops, refac
Some checks failed
/ Quality Check (push) Failing after 1m41s
/ Build (push) Successful in 1m36s

This commit is contained in:
Phani Pavan K
2025-10-19 13:06:50 +05:30
parent d4d2c5e3eb
commit d713cc8fa3
6 changed files with 218 additions and 50 deletions

View File

@@ -3,6 +3,8 @@ pub mod entry;
mod settings;
pub mod status;
use ratatui::widgets::TableState;
use crate::app::{
entry::Entry,
settings::Settings,
@@ -18,6 +20,7 @@ pub struct AppState {
pub currentlyEditing: Option<EditingField>,
pub entries: Vec<Entry>,
pub confDir: String,
pub tableState: TableState,
}
impl AppState {
@@ -32,6 +35,7 @@ impl AppState {
screen: CurrentScreen::Main,
entries: settings.entries,
confDir,
tableState: TableState::default().with_selected(0),
}
}
@@ -49,7 +53,8 @@ impl AppState {
self.fromPort = String::new();
self.toPort = String::new();
self.currentlyEditing = None;
self.tableState
.select(Some(self.entries.len() - 1 as usize));
EntryCreation::Success
}
_ => EntryCreation::PortValidationError,
@@ -104,4 +109,40 @@ impl AppState {
settings.entries = self.entries.clone();
settings.save(&self.confDir);
}
pub fn nextRow(&mut self) {
let i = match self.tableState.selected() {
Some(i) => {
if i >= self.entries.len() - 1 {
0
} else {
i + 1
}
}
None => 0,
};
self.tableState.select(Some(i));
}
pub fn prevRow(&mut self) {
let i = match self.tableState.selected() {
Some(i) => {
if i == 0 {
self.entries.len() - 1
} else {
i - 1
}
}
None => 0,
};
self.tableState.select(Some(i));
}
pub fn delCur(&mut self) {
if self.entries.is_empty() {
self.screen = CurrentScreen::Main;
return;
}
self.entries.remove(self.tableState.selected().unwrap());
}
}