diff --git a/card_stuffs/src/main.rs b/card_stuffs/src/main.rs index 57bf029..515899b 100644 --- a/card_stuffs/src/main.rs +++ b/card_stuffs/src/main.rs @@ -19,6 +19,7 @@ pub struct App { selected_card: Option, exit: bool, show_help: bool, + show_exit: bool, } const CARD_HEIGHT: u16 = 11; @@ -223,6 +224,8 @@ impl App { if self.show_help { show_help(frame, &area); + } else if self.show_exit { + show_exit(frame, &area); } } @@ -240,7 +243,11 @@ impl App { fn handle_key_event(&mut self, key_event: KeyEvent) { match key_event.code { - KeyCode::Char('q') => self.exit(), + KeyCode::Char('q') => { + if self.show_exit { self.exit() } + self.show_exit = true; + }, + KeyCode::Char('b') => self.show_exit = false, KeyCode::Char('d') => self.cards.deck_to_waste(), KeyCode::Char('w') => self.cards.waste_to_deck(), KeyCode::Char('1') => self.cards.num_cards_turned = 1, @@ -279,6 +286,21 @@ Press 'w' to put the waste pile back into the deck (you can only do this when th frame.render_widget(p.block(block), area); } +fn show_exit(frame: &mut Frame, area: &Rect) { + let block = Block::bordered().title("Exit?"); + let text = +"Really want to exit Legend of Soltar? +Press 'q' to Quit or 'b' to go back"; + let p = Paragraph::new(text).wrap(Wrap { trim: true }); + let vertical = Layout::vertical([Constraint::Max(10)]).flex(Flex::Center); + let horizontal = Layout::horizontal([Constraint::Percentage(70)]).flex(Flex::Center); + let [area] = vertical.areas(*area); + let [area] = horizontal.areas(area); + frame.render_widget(Clear, area); + frame.render_widget(p.block(block), area); +} + + fn deck_widget(cards_in_deck: &Vec) -> Paragraph<'static> { let card_image = format!(