Skip to main content

chatty_rs/app/ui/
loading.rs

1use ratatui::{
2    Frame,
3    layout::Rect,
4    style::{Modifier, Style},
5    text::{Line, Text},
6    widgets::{Block, BorderType, Borders, Padding, Paragraph},
7};
8
9#[derive(Default)]
10pub struct Loading<'a>(Line<'a>);
11
12impl<'a> Loading<'a> {
13    pub fn new(text: impl Into<Line<'a>>) -> Loading<'a> {
14        Loading(text.into())
15    }
16
17    fn value(&self) -> &Line {
18        &self.0
19    }
20
21    pub fn render(&self, frame: &mut Frame, rect: Rect) {
22        frame.render_widget(
23            Paragraph::new(Text::from(vec![self.value().clone()]))
24                .style(Style {
25                    add_modifier: Modifier::ITALIC,
26                    ..Default::default()
27                })
28                .block(
29                    Block::default()
30                        .borders(Borders::ALL)
31                        .border_type(BorderType::Rounded)
32                        .padding(Padding::new(1, 1, 0, 0)),
33                ),
34            rect,
35        );
36    }
37}