JHHM

lol-cal

terminal lolesports schedule viewer
git clone https://jhhm.no/repos/lol-cal.git

lol-cal/src/widgets/fillchar.rs

get raw file: fillchar.rs

1use ratatui::{buffer::Buffer, layout::Rect, style::Style, widgets::Widget};
2
3#[derive(Clone, Copy, Debug)]
4pub struct FillChar {
5    ch: char,
6    style: Style,
7}
8
9impl FillChar {
10    pub fn new(ch: char) -> Self {
11        Self {
12            ch,
13            style: Style::default(),
14        }
15    }
16
17    pub fn style(mut self, s: Style) -> Self {
18        self.style = s;
19        self
20    }
21}
22
23impl Widget for FillChar {
24    fn render(self, area: Rect, buf: &mut Buffer) {
25        let fill_line: String = std::iter::repeat(self.ch)
26            .take(area.width as usize)
27            .collect();
28
29        for y in area.y..area.y + area.height {
30            buf.set_string(area.x, y, &fill_line, self.style);
31        }
32    }
33}