diff --git a/src/app/status.rs b/src/app/status.rs index 438eee6..1c7262e 100644 --- a/src/app/status.rs +++ b/src/app/status.rs @@ -4,6 +4,7 @@ pub enum CurrentScreen { Settings, Delete, Exit, + SaveConfirm, } pub enum EditingField { diff --git a/src/main.rs b/src/main.rs index 5924677..8572f17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,10 +84,7 @@ fn runApp(app: &mut AppState, terminal: &mut Terminal) -> Result< } KeyCode::Char('s') => { if app.isHashDifferent() { - app.saveConfigToScript(); - app.saveConfigToSettingsFile(); - app.appStatus = AppStatus::Saved; - terminal.clear()?; + app.screen = CurrentScreen::SaveConfirm; } } KeyCode::F(2) => app.screen = CurrentScreen::Settings, @@ -184,6 +181,17 @@ fn runApp(app: &mut AppState, terminal: &mut Terminal) -> Result< } _ => {} }, + CurrentScreen::SaveConfirm => match key.code { + KeyCode::Enter => { + app.saveConfigToScript(); + app.saveConfigToSettingsFile(); + app.appStatus = AppStatus::Saved; + terminal.clear()?; + app.screen = CurrentScreen::Main; + } + KeyCode::Esc => app.screen = CurrentScreen::Main, + _ => {} + }, CurrentScreen::Exit => match key.code { KeyCode::Enter => { // app.saveConfigToSettingsFile(); diff --git a/src/ui/exitPrompt.rs b/src/ui/exitPrompt.rs index c77aaaa..ecb8d9f 100644 --- a/src/ui/exitPrompt.rs +++ b/src/ui/exitPrompt.rs @@ -4,17 +4,30 @@ use ratatui::{ widgets::{Block, Borders, Paragraph, Wrap}, }; -pub fn getExitPara<'a>() -> Paragraph<'a> { +pub fn getExitPara<'a>(isSaved: bool) -> Paragraph<'a> { let exitPopup = Block::default() .title("Exit Window") .borders(Borders::ALL) .style(Style::default().bg(Color::Rgb(42, 61, 69))) .border_style(Style::default().fg(Color::Red)); + let saveDialog = { + if isSaved { + ( + Line::from("All Changes Saved"), + Line::from("It is safe to exit."), + ) + } else { + ( + Line::from("ANY UNSAVED CHANGES WILL BE DISCARDED."), + Line::from("Press (s) to save from main screen."), + ) + } + }; let exitText = Text::from(vec![ Line::from("Exit the app?"), - Line::from("ANY UNSAVED CHANGES WILL BE DISCARDED."), - Line::from("Press (s) to save from the main screen."), + saveDialog.0, + saveDialog.1, ]); Paragraph::new(exitText) .block(exitPopup) diff --git a/src/ui/header.rs b/src/ui/header.rs index 220e370..157dcb4 100644 --- a/src/ui/header.rs +++ b/src/ui/header.rs @@ -27,6 +27,10 @@ pub fn getHeaderScreen<'a>(scr: &'a CurrentScreen) -> (Color, Span<'a>) { Color::Magenta, Span::styled("Delete", Style::default().fg(Color::Magenta)), ), + CurrentScreen::SaveConfirm => ( + Color::Yellow, + Span::styled("Confirmation", Style::default().fg(Color::Yellow)), + ), } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 5816a7d..b1eb6b2 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -14,7 +14,7 @@ use ratatui::{ widgets::{Block, Borders, Clear, Paragraph}, }; -use crate::app::status::CurrentScreen; +use crate::app::status::{AppStatus, CurrentScreen}; use crate::app::{AppState, status::EditingField}; use crate::ui::centeredRect::centered_rect; use crate::ui::textHints::hints; @@ -69,7 +69,15 @@ pub fn ui(frame: &mut Frame, app: &mut AppState) { if let CurrentScreen::Exit = app.screen { let area = centered_rect(60, 25, titleBodyChunks[1]); frame.render_widget(Clear, area); - frame.render_widget(exitPrompt::getExitPara(), area); + frame.render_widget( + exitPrompt::getExitPara({ + match app.appStatus { + AppStatus::Saved | AppStatus::Welcome => true, + _ => false, + } + }), + area, + ); } // ------------------------------------------- @@ -148,6 +156,7 @@ pub fn ui(frame: &mut Frame, app: &mut AppState) { CurrentScreen::Settings => hints::settingsHints(), CurrentScreen::Delete => hints::delHints(), CurrentScreen::Exit => hints::exitHints(), + CurrentScreen::SaveConfirm => hints::saveConfirmationHints(), } }; diff --git a/src/ui/textHints.rs b/src/ui/textHints.rs index 95bb7bc..8e5dbdf 100644 --- a/src/ui/textHints.rs +++ b/src/ui/textHints.rs @@ -43,4 +43,11 @@ pub mod hints { pub fn settingsHints<'a>() -> Text<'a> { Text::from(Line::from("").style(Style::default().fg(Color::Red))) } + + pub fn saveConfirmationHints<'a>() -> Text<'a> { + Text::from(vec![ + Line::from("(entr) Save and reload service").style(Style::default().fg(Color::Yellow)), + Line::from("(esc) Cancel").style(Style::default().fg(Color::LightRed)), + ]) + } }