mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
feat(interactive): Prompt before exiting (#1146)
This commit is contained in:
parent
6bf5069d0c
commit
dcd240a50a
@ -13,7 +13,10 @@ use crate::commands::{
|
||||
ls::{NodeLs, Summary},
|
||||
tui::{
|
||||
restore::Restore,
|
||||
widgets::{popup_text, Draw, PopUpText, ProcessEvent, SelectTable, WithBlock},
|
||||
widgets::{
|
||||
popup_prompt, popup_text, Draw, PopUpPrompt, PopUpText, ProcessEvent, PromptResult,
|
||||
SelectTable, WithBlock,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -22,6 +25,7 @@ enum CurrentScreen<'a, P, S> {
|
||||
Snapshot,
|
||||
ShowHelp(PopUpText),
|
||||
Restore(Restore<'a, P, S>),
|
||||
PromptExit(PopUpPrompt),
|
||||
}
|
||||
|
||||
const INFO_TEXT: &str =
|
||||
@ -190,7 +194,10 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
|
||||
}
|
||||
}
|
||||
Esc | Char('q') => {
|
||||
return Ok(SnapshotResult::Exit);
|
||||
self.current_screen = CurrentScreen::PromptExit(popup_prompt(
|
||||
"exit rustic",
|
||||
"do you want to exit? (y/n)".into(),
|
||||
));
|
||||
}
|
||||
Char('?') => {
|
||||
self.current_screen =
|
||||
@ -237,6 +244,11 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
|
||||
self.current_screen = CurrentScreen::Snapshot;
|
||||
}
|
||||
}
|
||||
CurrentScreen::PromptExit(prompt) => match prompt.input(event) {
|
||||
PromptResult::Ok => return Ok(SnapshotResult::Exit),
|
||||
PromptResult::Cancel => self.current_screen = CurrentScreen::Snapshot,
|
||||
PromptResult::None => {}
|
||||
},
|
||||
}
|
||||
Ok(SnapshotResult::None)
|
||||
}
|
||||
@ -263,6 +275,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
|
||||
match &mut self.current_screen {
|
||||
CurrentScreen::Snapshot | CurrentScreen::Restore(_) => {}
|
||||
CurrentScreen::ShowHelp(popup) => popup.draw(area, f),
|
||||
CurrentScreen::PromptExit(popup) => popup.draw(area, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ enum CurrentScreen<'a, P, S> {
|
||||
EnterSetTags(PopUpInput),
|
||||
EnterRemoveTags(PopUpInput),
|
||||
PromptWrite(PopUpPrompt),
|
||||
PromptExit(PopUpPrompt),
|
||||
Dir(Snapshot<'a, P, S>),
|
||||
}
|
||||
|
||||
@ -715,7 +716,12 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
|
||||
}
|
||||
} else {
|
||||
match key.code {
|
||||
Esc | Char('q') => return Ok(true),
|
||||
Esc | Char('q') => {
|
||||
self.current_screen = CurrentScreen::PromptExit(popup_prompt(
|
||||
"exit rustic",
|
||||
"do you want to exit? (y/n)".into(),
|
||||
));
|
||||
}
|
||||
Char('f') => self.toggle_to_forget(),
|
||||
F(5) => self.reread()?,
|
||||
Enter => {
|
||||
@ -842,6 +848,11 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
|
||||
PromptResult::Cancel => self.current_screen = CurrentScreen::Snapshots,
|
||||
PromptResult::None => {}
|
||||
},
|
||||
CurrentScreen::PromptExit(prompt) => match prompt.input(event) {
|
||||
PromptResult::Ok => return Ok(true),
|
||||
PromptResult::Cancel => self.current_screen = CurrentScreen::Snapshots,
|
||||
PromptResult::None => {}
|
||||
},
|
||||
CurrentScreen::Dir(dir) => match dir.input(event)? {
|
||||
SnapshotResult::Exit => return Ok(true),
|
||||
SnapshotResult::Return => self.current_screen = CurrentScreen::Snapshots,
|
||||
@ -879,7 +890,9 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
|
||||
| CurrentScreen::EnterAddTags(popup)
|
||||
| CurrentScreen::EnterSetTags(popup)
|
||||
| CurrentScreen::EnterRemoveTags(popup) => popup.draw(area, f),
|
||||
CurrentScreen::PromptWrite(popup) => popup.draw(area, f),
|
||||
CurrentScreen::PromptWrite(popup) | CurrentScreen::PromptExit(popup) => {
|
||||
popup.draw(area, f);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user