use ratatui::{
buffer::Buffer,
layout::Rect,
style::Style,
text::Line,
widgets::{Clear, Widget},
};
use crate::ui::tui::session::Session;
pub struct HeaderWidget<'a> {
session: &'a Session,
lines: Vec<Line<'static>>,
custom_style: Option<Style>,
}
impl<'a> HeaderWidget<'a> {
pub fn new(session: &'a Session) -> Self {
Self {
session,
lines: Vec::new(),
custom_style: None,
}
}
#[must_use]
pub fn lines(mut self, lines: Vec<Line<'static>>) -> Self {
self.lines = lines;
self
}
#[must_use]
pub fn custom_style(mut self, style: Style) -> Self {
self.custom_style = Some(style);
self
}
}
impl<'a> Widget for HeaderWidget<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
Clear.render(area, buf);
if area.height == 0 || area.width == 0 {
return;
}
let paragraph = self.session.build_header_paragraph(&self.lines);
paragraph.render(area, buf);
}
}