Skip to main content

vtcode_tui/core_tui/widgets/
header.rs

1use ratatui::{
2    buffer::Buffer,
3    layout::Rect,
4    style::Style,
5    text::Line,
6    widgets::{Clear, Widget},
7};
8
9use crate::ui::tui::session::Session;
10
11/// Widget for rendering the header area with session metadata
12///
13/// This widget displays:
14/// - Provider and model information
15/// - Reasoning mode status
16/// - Tool policy summary
17/// - Workspace trust level
18/// - Git status
19/// - Plan progress (if applicable)
20/// - Suggestions or highlights
21///
22/// # Example
23/// ```ignore
24/// HeaderWidget::new(session)
25///     .lines(header_lines)
26///     .custom_style(style)
27///     .render(area, buf);
28/// ```
29pub struct HeaderWidget<'a> {
30    session: &'a Session,
31    lines: Vec<Line<'static>>,
32    custom_style: Option<Style>,
33}
34
35impl<'a> HeaderWidget<'a> {
36    /// Create a new HeaderWidget with required parameters
37    pub fn new(session: &'a Session) -> Self {
38        Self {
39            session,
40            lines: Vec::new(),
41            custom_style: None,
42        }
43    }
44
45    /// Set the header lines to display
46    #[must_use]
47    pub fn lines(mut self, lines: Vec<Line<'static>>) -> Self {
48        self.lines = lines;
49        self
50    }
51
52    /// Set a custom style for the header
53    #[must_use]
54    pub fn custom_style(mut self, style: Style) -> Self {
55        self.custom_style = Some(style);
56        self
57    }
58}
59
60impl<'a> Widget for HeaderWidget<'a> {
61    fn render(self, area: Rect, buf: &mut Buffer) {
62        Clear.render(area, buf);
63
64        if area.height == 0 || area.width == 0 {
65            return;
66        }
67
68        let paragraph = self.session.build_header_paragraph(&self.lines);
69        paragraph.render(area, buf);
70    }
71}