Compare commits
3 Commits
1aea9c4930
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8353726c77 | |||
|
|
c2d62b59fa | ||
|
|
059415dca2 |
@@ -19,3 +19,8 @@ This project is in very early stage of development. Use it at your own risk.
|
||||
Follow [LICENSE](LICENSE).
|
||||
|
||||
Also follow [.NOAI](.NOAI).
|
||||
|
||||
|
||||
---
|
||||
|
||||
~ A Grammer Society Project.
|
||||
@@ -4,6 +4,7 @@ pub enum CurrentScreen {
|
||||
Settings,
|
||||
Delete,
|
||||
Exit,
|
||||
SaveConfirm,
|
||||
}
|
||||
|
||||
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') => {
|
||||
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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user