prototty_common/
text_info.rs

1use prototty_render::{Rgb24, ViewCell};
2
3/// Rich text settings
4#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
5#[derive(Debug, Clone, Copy)]
6pub struct TextInfo {
7    pub foreground_colour: Option<Rgb24>,
8    pub background_colour: Option<Rgb24>,
9    pub underline: bool,
10    pub bold: bool,
11}
12
13impl Default for TextInfo {
14    fn default() -> Self {
15        Self {
16            foreground_colour: None,
17            background_colour: None,
18            underline: false,
19            bold: false,
20        }
21    }
22}
23
24impl TextInfo {
25    pub fn foreground_colour(self, colour: Rgb24) -> Self {
26        Self {
27            foreground_colour: Some(colour),
28            ..self
29        }
30    }
31    pub fn background_colour(self, colour: Rgb24) -> Self {
32        Self {
33            background_colour: Some(colour),
34            ..self
35        }
36    }
37    pub fn underline(self) -> Self {
38        Self {
39            underline: true,
40            ..self
41        }
42    }
43    pub fn bold(self) -> Self {
44        Self { bold: true, ..self }
45    }
46    pub fn view_cell_info(&self, character: char) -> ViewCell {
47        ViewCell {
48            character: Some(character),
49            foreground: self.foreground_colour,
50            background: self.background_colour,
51            underline: Some(self.underline),
52            bold: Some(self.bold),
53        }
54    }
55}