matchmaker/ui/
display.rs

1#![allow(unused)]
2use log::debug;
3use ratatui::{
4    style::{Style, Stylize},
5    widgets::Paragraph,
6};
7
8use crate::{config::{DisplayConfig, StringOrVec}, utils::text::left_pad};
9
10#[derive(Debug, Clone)]
11pub struct DisplayUI {
12    height: u16,
13    pub text: String,
14    pub show: bool,
15    pub config: DisplayConfig,
16}
17
18impl DisplayUI {
19    pub fn new(config: DisplayConfig) -> Self {
20        let text = match &config.content {
21            Some(StringOrVec::String(s)) => s.clone(),
22            // todo
23            _ => String::new(),
24        };
25
26        Self {
27            height: text.lines().count() as u16,
28            show: config.content.is_some(),
29            text,
30            config,
31        }
32    }
33
34    pub fn height(&self) -> u16 {
35        if !self.show {
36            return 0;
37        }
38        let mut height = self.height;
39        height += self.config.border.height();
40
41        height
42    }
43
44    pub fn set(&mut self, text: String) {
45        self.height = text.lines().count() as u16;
46        self.text = text;
47    }
48
49    pub fn make_display(&self, result_indentation: usize) -> Paragraph<'_> {
50        let text = if self.config.match_indent {
51            left_pad(&self.text, result_indentation)
52        } else {
53            self.text.clone()
54        };
55        debug!("{result_indentation}, {}, {text}", self.config.match_indent);
56
57        let mut ret = Paragraph::new(text)
58        .style(Style::default().fg(self.config.fg))
59        .add_modifier(self.config.modifier);
60
61
62
63        ret = ret.block(self.config.border.as_block());
64
65        ret
66    }
67}