Skip to main content

rab/tui/components/
dynamic_lines.rs

1use crate::tui::Component;
2
3/// A component that wraps a `Vec<String>` buffer that can be updated dynamically.
4/// Used for sections whose content changes each frame (pending text, status, etc.).
5pub struct DynamicLines {
6    lines: Vec<String>,
7}
8
9impl DynamicLines {
10    pub fn new() -> Self {
11        Self { lines: Vec::new() }
12    }
13
14    /// Set the lines for this component.
15    pub fn set_lines(&mut self, new_lines: Vec<String>) {
16        self.lines = new_lines;
17    }
18
19    /// Clear the lines.
20    pub fn clear(&mut self) {
21        self.lines.clear();
22    }
23}
24
25impl Default for DynamicLines {
26    fn default() -> Self {
27        Self::new()
28    }
29}
30
31impl Component for DynamicLines {
32    fn render(&mut self, _width: usize) -> Vec<String> {
33        self.lines.clone()
34    }
35
36    fn invalidate(&mut self) {
37        // No cache — always returns current buffer
38    }
39}