rab/tui/components/
lines_component.rs1use std::cell::RefCell;
2
3use crate::tui::Component;
4
5pub struct LinesComponent {
12 pub lines: RefCell<Vec<String>>,
14}
15
16impl LinesComponent {
17 pub fn new() -> Self {
18 Self {
19 lines: RefCell::new(Vec::new()),
20 }
21 }
22
23 pub fn set_lines(&self, new_lines: Vec<String>) {
25 *self.lines.borrow_mut() = new_lines;
26 }
27
28 pub fn push(&self, line: String) {
30 self.lines.borrow_mut().push(line);
31 }
32
33 pub fn extend(&self, lines: impl IntoIterator<Item = String>) {
35 self.lines.borrow_mut().extend(lines);
36 }
37
38 pub fn clear(&self) {
40 self.lines.borrow_mut().clear();
41 }
42}
43
44impl Default for LinesComponent {
45 fn default() -> Self {
46 Self::new()
47 }
48}
49
50impl Component for LinesComponent {
51 fn render(&self, _width: usize) -> Vec<String> {
52 self.lines.borrow().clone()
53 }
54
55 fn invalidate(&mut self) {
56 }
58}