ratatui_toolkit/primitives/statusline/constructors/
mod.rs

1use ratatui::style::Style;
2use ratatui::text::Line;
3
4use crate::primitives::statusline::{OperationalMode, StatusLineStacked, StyledStatusLine};
5
6impl<'a> StatusLineStacked<'a> {
7    pub fn new() -> Self {
8        Self {
9            style: Style::default(),
10            left: Vec::new(),
11            center_margin: 0,
12            center: Line::default(),
13            right: Vec::new(),
14            phantom: std::marker::PhantomData,
15        }
16    }
17
18    pub fn style(mut self, style: Style) -> Self {
19        self.style = style;
20        self
21    }
22
23    pub fn start(mut self, text: impl Into<Line<'a>>, gap: impl Into<Line<'a>>) -> Self {
24        self.left.push((text.into(), gap.into()));
25        self
26    }
27
28    pub fn start_bare(mut self, text: impl Into<Line<'a>>) -> Self {
29        self.left.push((text.into(), "".into()));
30        self
31    }
32
33    pub fn center_margin(mut self, margin: u16) -> Self {
34        self.center_margin = margin;
35        self
36    }
37
38    pub fn center(mut self, text: impl Into<Line<'a>>) -> Self {
39        self.center = text.into();
40        self
41    }
42
43    pub fn end(mut self, text: impl Into<Line<'a>>, gap: impl Into<Line<'a>>) -> Self {
44        self.right.push((text.into(), gap.into()));
45        self
46    }
47
48    pub fn end_bare(mut self, text: impl Into<Line<'a>>) -> Self {
49        self.right.push((text.into(), "".into()));
50        self
51    }
52}
53
54impl<'a> StyledStatusLine<'a> {
55    pub fn new() -> Self {
56        Self {
57            mode: OperationalMode::Operational,
58            title: " WESTINGHOUSE[STATUS]2 ",
59            center_text: String::new(),
60            render_count: 0,
61            event_count: 0,
62            render_time_us: 0,
63            event_time_us: 0,
64            message_count: 0,
65            use_slants: true,
66        }
67    }
68
69    pub fn mode(mut self, mode: OperationalMode) -> Self {
70        self.mode = mode;
71        self
72    }
73
74    pub fn title(mut self, title: &'a str) -> Self {
75        self.title = title;
76        self
77    }
78
79    pub fn center_text(mut self, text: impl Into<String>) -> Self {
80        self.center_text = text.into();
81        self
82    }
83
84    pub fn render_metrics(mut self, count: usize, time_us: u64) -> Self {
85        self.render_count = count;
86        self.render_time_us = time_us;
87        self
88    }
89
90    pub fn event_metrics(mut self, count: usize, time_us: u64) -> Self {
91        self.event_count = count;
92        self.event_time_us = time_us;
93        self
94    }
95
96    pub fn message_count(mut self, count: u32) -> Self {
97        self.message_count = count;
98        self
99    }
100
101    pub fn use_slants(mut self, use_slants: bool) -> Self {
102        self.use_slants = use_slants;
103        self
104    }
105}