Skip to content

Commit

Permalink
feat(interactive): Prompt before exiting (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Apr 30, 2024
1 parent 6bf5069 commit dcd240a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/commands/tui/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};

Expand All @@ -22,6 +25,7 @@ enum CurrentScreen<'a, P, S> {
Snapshot,
ShowHelp(PopUpText),
Restore(Restore<'a, P, S>),
PromptExit(PopUpPrompt),
}

const INFO_TEXT: &str =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
}
Expand All @@ -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),
}
}
}
17 changes: 15 additions & 2 deletions src/commands/tui/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum CurrentScreen<'a, P, S> {
EnterSetTags(PopUpInput),
EnterRemoveTags(PopUpInput),
PromptWrite(PopUpPrompt),
PromptExit(PopUpPrompt),
Dir(Snapshot<'a, P, S>),
}

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
_ => {}
}
}
Expand Down

0 comments on commit dcd240a

Please sign in to comment.