vtcode_tui/core_tui/widgets/
header.rs1use 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
11pub struct HeaderWidget<'a> {
30 session: &'a Session,
31 lines: Vec<Line<'static>>,
32 custom_style: Option<Style>,
33}
34
35impl<'a> HeaderWidget<'a> {
36 pub fn new(session: &'a Session) -> Self {
38 Self {
39 session,
40 lines: Vec::new(),
41 custom_style: None,
42 }
43 }
44
45 #[must_use]
47 pub fn lines(mut self, lines: Vec<Line<'static>>) -> Self {
48 self.lines = lines;
49 self
50 }
51
52 #[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}