handle * ip, ui refac, fix #1 to handle .conf
Some checks failed
/ Quality Check (push) Failing after 1m5s
/ Build (push) Successful in 1m7s

This commit is contained in:
Phani Pavan K
2025-10-26 11:45:08 +05:30
parent 9314e97c60
commit f83d6038c8
7 changed files with 158 additions and 124 deletions

View File

@@ -2,6 +2,9 @@
mod app;
mod ui;
use crate::app::status::{
AppStatus, CurrentScreen, EditingField, EntryValError, entryValError2Field,
};
use crate::ui::ui;
use app::AppState;
use color_eyre::Result;
@@ -14,12 +17,9 @@ use ratatui::crossterm::terminal::{
EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode,
};
use ratatui::prelude::{Backend, CrosstermBackend};
use std::env::var;
use std::io;
use crate::app::status::{
AppStatus, CurrentScreen, EditingField, EntryValError, entryValError2Field,
};
fn main() -> Result<()> {
enable_raw_mode()?;
let mut stderr = io::stderr(); // This is a special case. Normally using stdout is fine
@@ -27,10 +27,13 @@ fn main() -> Result<()> {
let backend = CrosstermBackend::new(stderr);
let mut terminal = Terminal::new(backend)?;
let configHome = var("XDG_CONFIG_HOME")
.or_else(|_| var("HOME").map(|home| format!("{}/.config", home)))
.unwrap_or("~/.config".to_string());
// create app and run it
let mut app = AppState::new("./conf.json".to_string());
let mut appSettings = AppState::new(format!("{configHome}/steckbrett.conf"));
// app.load();
let res = runApp(&mut app, &mut terminal);
let _ = runApp(&mut appSettings, &mut terminal);
disable_raw_mode()?;
execute!(
terminal.backend_mut(),
@@ -39,17 +42,15 @@ fn main() -> Result<()> {
)?;
terminal.show_cursor()?;
if let Ok(do_print) = res {
if do_print {
app.print();
}
} else if let Err(err) = res {
println!("{err:?}");
}
// match res {
// Ok(ent) => println!("{ent} entries "),
// _ => {}
// }
Ok(())
}
fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<bool> {
fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<usize> {
loop {
terminal.draw(|f| ui(f, app))?; // from ui.rs
if let Event::Key(key) = event::read()? {
@@ -86,6 +87,7 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
app.saveConfigToScript();
app.saveConfigToSettingsFile();
app.appStatus = AppStatus::Saved;
terminal.clear()?;
}
}
KeyCode::F(2) => app.screen = CurrentScreen::Settings,
@@ -184,9 +186,9 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
},
CurrentScreen::Exit => match key.code {
KeyCode::Enter => {
app.saveConfigToSettingsFile();
app.saveConfigToScript();
return Ok(true);
// app.saveConfigToSettingsFile();
// app.saveConfigToScript();
return Ok(app.settings.entries.len());
}
KeyCode::Esc | KeyCode::Char('m') => app.screen = CurrentScreen::Main,
_ => {}