Compare commits
2 Commits
1aea9c4930
...
c2d62b59fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2d62b59fa | ||
|
|
059415dca2 |
@@ -4,6 +4,7 @@ pub enum CurrentScreen {
|
|||||||
Settings,
|
Settings,
|
||||||
Delete,
|
Delete,
|
||||||
Exit,
|
Exit,
|
||||||
|
SaveConfirm,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EditingField {
|
pub enum EditingField {
|
||||||
|
|||||||
16
src/main.rs
16
src/main.rs
@@ -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();
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,13 @@ 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(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::Settings => hints::settingsHints(),
|
||||||
CurrentScreen::Delete => hints::delHints(),
|
CurrentScreen::Delete => hints::delHints(),
|
||||||
CurrentScreen::Exit => hints::exitHints(),
|
CurrentScreen::Exit => hints::exitHints(),
|
||||||
|
CurrentScreen::SaveConfirm => hints::saveConfirmationHints(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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)),
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user