envelope_cli/tui/dialogs/
confirm.rs

1//! Confirmation dialog
2//!
3//! Simple yes/no confirmation
4
5use ratatui::{
6    style::{Color, Modifier, Style},
7    text::{Line, Span},
8    widgets::{Block, Borders, Clear, Paragraph, Wrap},
9    Frame,
10};
11
12use crate::tui::layout::centered_rect_fixed;
13
14/// Render a confirmation dialog
15pub fn render(frame: &mut Frame, message: &str) {
16    let area = centered_rect_fixed(50, 7, frame.area());
17
18    // Clear the background
19    frame.render_widget(Clear, area);
20
21    let block = Block::default()
22        .title(" Confirm ")
23        .title_style(
24            Style::default()
25                .fg(Color::Yellow)
26                .add_modifier(Modifier::BOLD),
27        )
28        .borders(Borders::ALL)
29        .border_style(Style::default().fg(Color::Yellow));
30
31    let lines = vec![
32        Line::from(""),
33        Line::from(Span::styled(message, Style::default().fg(Color::White))),
34        Line::from(""),
35        Line::from(vec![
36            Span::styled("[Y]", Style::default().fg(Color::Green)),
37            Span::raw(" Yes  "),
38            Span::styled("[N]", Style::default().fg(Color::Red)),
39            Span::raw(" No  "),
40            Span::styled("[Esc]", Style::default().fg(Color::Yellow)),
41            Span::raw(" Cancel"),
42        ]),
43    ];
44
45    let paragraph = Paragraph::new(lines)
46        .block(block)
47        .wrap(Wrap { trim: false });
48
49    frame.render_widget(paragraph, area);
50}