Skip to main content

stynx_code_tui/widgets/
summary_bar.rs

1use ratatui::{
2    buffer::Buffer,
3    layout::Rect,
4    style::{Modifier, Style},
5    text::{Line, Span},
6    widgets::{Paragraph, Widget},
7};
8
9use crate::theme;
10
11pub struct SummaryBar<'a> {
12    items: &'a [String],
13}
14
15impl<'a> SummaryBar<'a> {
16    pub fn new(items: &'a [String]) -> Self {
17        Self { items }
18    }
19}
20
21impl<'a> Widget for SummaryBar<'a> {
22    fn render(self, area: Rect, buf: &mut Buffer) {
23        let bg = theme::SURFACE();
24
25        for x in area.x..area.x + area.width {
26            buf[(x, area.y)].set_style(Style::default().bg(bg));
27        }
28
29        let check = Span::styled(
30            " ✓ ",
31            Style::default()
32                .fg(theme::SUCCESS())
33                .bg(bg)
34                .add_modifier(Modifier::BOLD),
35        );
36
37        let mut spans: Vec<Span<'static>> = vec![check];
38
39        let pill_bg = theme::OVERLAY();
40        let pill_fg = theme::TEXT();
41        let sep_fg = theme::MUTED();
42
43        for (i, item) in self.items.iter().enumerate() {
44            if i > 0 {
45                spans.push(Span::styled(
46                    "  ",
47                    Style::default().fg(sep_fg).bg(bg),
48                ));
49            }
50            spans.push(Span::styled(
51                format!(" {} ", item),
52                Style::default()
53                    .fg(pill_fg)
54                    .bg(pill_bg)
55                    .add_modifier(Modifier::BOLD),
56            ));
57        }
58
59        Paragraph::new(Line::from(spans))
60            .style(Style::default().bg(bg))
61            .render(area, buf);
62    }
63}