Compare commits

...

2 Commits

Author SHA1 Message Date
Phani Pavan K
c2d62b59fa added clippy suggestions
All checks were successful
/ Quality Check (push) Successful in 2m8s
/ Build (push) Successful in 2m10s
2025-11-10 14:25:11 +05:30
Phani Pavan K
059415dca2 added save confirmation, changed exit dialog 2025-11-10 14:19:58 +05:30
6 changed files with 49 additions and 9 deletions

View File

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

View File

@@ -84,10 +84,7 @@ fn runApp<B: Backend>(app: &mut AppState, terminal: &mut Terminal<B>) -> 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<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 {
KeyCode::Enter => {
// app.saveConfigToSettingsFile();

View File

@@ -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)

View File

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

View File

@@ -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,13 @@ 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(matches!(
app.appStatus,
AppStatus::Saved | AppStatus::Welcome
)),
area,
);
}
// -------------------------------------------
@@ -148,6 +154,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(),
}
};

View File

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