Skip to main content

codetether_agent/tui/app/watchdog/
notification.rs

1//! Watchdog notification UI widget.
2
3use ratatui::Frame;
4use ratatui::layout::Rect;
5use ratatui::style::{Color, Modifier, Style};
6use ratatui::text::{Line, Span};
7use ratatui::widgets::{Block, Borders, Clear, Paragraph, Wrap};
8
9use crate::tui::app::state::AppState;
10
11/// Render the watchdog notification popup centered in the chat area.
12pub fn render_watchdog_notification(f: &mut Frame, area: Rect, state: &AppState) {
13    let Some(ref notif) = state.watchdog_notification else {
14        return;
15    };
16    let width = (area.width.min(60)).max(30);
17    let height = 5u16;
18    let x = area.x + (area.width.saturating_sub(width)) / 2;
19    let y = area.y + (area.height.saturating_sub(height)) / 2;
20    let popup = Rect::new(x, y, width, height);
21
22    let text = vec![
23        Line::from(Span::styled(
24            &notif.message,
25            Style::default().fg(Color::Yellow),
26        )),
27        Line::from(""),
28        Line::from(vec![
29            Span::styled(
30                "[Esc] Dismiss ",
31                Style::default().add_modifier(Modifier::BOLD),
32            ),
33            Span::styled("[Ctrl+X] Cancel", Style::default().fg(Color::Red)),
34        ]),
35    ];
36    let para = Paragraph::new(text)
37        .block(Block::default().borders(Borders::ALL).title("Watchdog"))
38        .wrap(Wrap { trim: true });
39    f.render_widget(Clear, popup);
40    f.render_widget(para, popup);
41}