added save confirmation, changed exit dialog

This commit is contained in:
Phani Pavan K
2025-11-10 14:19:58 +05:30
parent 1aea9c4930
commit 059415dca2
6 changed files with 51 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ pub enum CurrentScreen {
Settings, Settings,
Delete, Delete,
Exit, Exit,
SaveConfirm,
} }
pub enum EditingField { pub enum EditingField {

View File

@@ -84,10 +84,7 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> Result<
} }
KeyCode::Char('s') => { KeyCode::Char('s') => {
if app.isHashDifferent() { if app.isHashDifferent() {
app.saveConfigToScript(); app.screen = CurrentScreen::SaveConfirm;
app.saveConfigToSettingsFile();
app.appStatus = AppStatus::Saved;
terminal.clear()?;
} }
} }
KeyCode::F(2) => app.screen = CurrentScreen::Settings, KeyCode::F(2) => app.screen = CurrentScreen::Settings,
@@ -184,6 +181,17 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> 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 { CurrentScreen::Exit => match key.code {
KeyCode::Enter => { KeyCode::Enter => {
// app.saveConfigToSettingsFile(); // app.saveConfigToSettingsFile();

View File

@@ -4,17 +4,30 @@ use ratatui::{
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph, Wrap},
}; };
pub fn getExitPara<'a>() -> Paragraph<'a> { pub fn getExitPara<'a>(isSaved: bool) -> Paragraph<'a> {
let exitPopup = Block::default() let exitPopup = Block::default()
.title("Exit Window") .title("Exit Window")
.borders(Borders::ALL) .borders(Borders::ALL)
.style(Style::default().bg(Color::Rgb(42, 61, 69))) .style(Style::default().bg(Color::Rgb(42, 61, 69)))
.border_style(Style::default().fg(Color::Red)); .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![ let exitText = Text::from(vec![
Line::from("Exit the app?"), Line::from("Exit the app?"),
Line::from("ANY UNSAVED CHANGES WILL BE DISCARDED."), saveDialog.0,
Line::from("Press (s) to save from the main screen."), saveDialog.1,
]); ]);
Paragraph::new(exitText) Paragraph::new(exitText)
.block(exitPopup) .block(exitPopup)

View File

@@ -27,6 +27,10 @@ pub fn getHeaderScreen<'a>(scr: &'a CurrentScreen) -> (Color, Span<'a>) {
Color::Magenta, Color::Magenta,
Span::styled("Delete", Style::default().fg(Color::Magenta)), Span::styled("Delete", Style::default().fg(Color::Magenta)),
), ),
CurrentScreen::SaveConfirm => (
Color::Yellow,
Span::styled("Confirmation", Style::default().fg(Color::Yellow)),
),
} }
} }

View File

@@ -14,7 +14,7 @@ use ratatui::{
widgets::{Block, Borders, Clear, Paragraph}, widgets::{Block, Borders, Clear, Paragraph},
}; };
use crate::app::status::CurrentScreen; use crate::app::status::{AppStatus, CurrentScreen};
use crate::app::{AppState, status::EditingField}; use crate::app::{AppState, status::EditingField};
use crate::ui::centeredRect::centered_rect; use crate::ui::centeredRect::centered_rect;
use crate::ui::textHints::hints; use crate::ui::textHints::hints;
@@ -69,7 +69,15 @@ pub fn ui(frame: &mut Frame, app: &mut AppState) {
if let CurrentScreen::Exit = app.screen { if let CurrentScreen::Exit = app.screen {
let area = centered_rect(60, 25, titleBodyChunks[1]); let area = centered_rect(60, 25, titleBodyChunks[1]);
frame.render_widget(Clear, area); 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::Settings => hints::settingsHints(),
CurrentScreen::Delete => hints::delHints(), CurrentScreen::Delete => hints::delHints(),
CurrentScreen::Exit => hints::exitHints(), CurrentScreen::Exit => hints::exitHints(),
CurrentScreen::SaveConfirm => hints::saveConfirmationHints(),
} }
}; };

View File

@@ -43,4 +43,11 @@ pub mod hints {
pub fn settingsHints<'a>() -> Text<'a> { pub fn settingsHints<'a>() -> Text<'a> {
Text::from(Line::from("").style(Style::default().fg(Color::Red))) 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)),
])
}
} }