Skip to main content

stynx_code_tui/widgets/
quit_confirm.rs

1use ratatui::{
2    buffer::Buffer,
3    layout::Rect,
4    style::{Modifier, Style},
5    text::{Line, Span},
6    widgets::{Clear, Paragraph, Widget},
7};
8
9use crate::theme;
10
11pub struct QuitConfirmDialog;
12
13impl Widget for QuitConfirmDialog {
14    fn render(self, area: Rect, buf: &mut Buffer) {
15        let w: u16 = 36;
16        let h: u16 = 4;
17        let x = area.x + area.width.saturating_sub(w) / 2;
18        let y = area.y + area.height.saturating_sub(h) / 2;
19        let dialog = Rect { x, y, width: w.min(area.width), height: h };
20
21        Clear.render(dialog, buf);
22
23        for dy in 0..dialog.height {
24            for dx in 0..dialog.width {
25                buf[(dialog.x + dx, dialog.y + dy)]
26                    .set_style(Style::default().bg(theme::BACKGROUND_PANEL()));
27            }
28            buf[(dialog.x, dialog.y + dy)]
29                .set_char('▌')
30                .set_style(Style::default().fg(theme::ERROR()).bg(theme::BACKGROUND_PANEL()));
31        }
32
33        let inner = Rect {
34            x: dialog.x + 2,
35            y: dialog.y + 1,
36            width: dialog.width.saturating_sub(3),
37            height: dialog.height.saturating_sub(2),
38        };
39
40        let lines = vec![
41            Line::from(Span::styled(
42                "Quit stynx?",
43                Style::default().fg(theme::TEXT()).add_modifier(Modifier::BOLD),
44            )),
45            Line::from(vec![
46                Span::styled("y", Style::default().fg(theme::SUCCESS()).add_modifier(Modifier::BOLD)),
47                Span::styled(" confirm  ", Style::default().fg(theme::MUTED())),
48                Span::styled("any key", Style::default().fg(theme::ERROR()).add_modifier(Modifier::BOLD)),
49                Span::styled(" cancel", Style::default().fg(theme::MUTED())),
50            ]),
51        ];
52
53        Paragraph::new(lines).render(inner, buf);
54    }
55}