1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use prototty::{ViewCell, Rgb24};

/// Rich text settings
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct TextInfo {
    pub foreground_colour: Option<Rgb24>,
    pub background_colour: Option<Rgb24>,
    pub underline: bool,
    pub bold: bool,
}

impl Default for TextInfo {
    fn default() -> Self {
        Self {
            foreground_colour: None,
            background_colour: None,
            underline: false,
            bold: false,
        }
    }
}

impl TextInfo {
    pub fn foreground_colour(self, colour: Rgb24) -> Self {
        Self { foreground_colour: Some(colour), .. self }
    }
    pub fn background_colour(self, colour: Rgb24) -> Self {
        Self { background_colour: Some(colour), .. self }
    }
    pub fn underline(self) -> Self {
        Self { underline: true, .. self }
    }
    pub fn bold(self) -> Self {
        Self { bold: true, .. self }
    }
    pub fn write_cell<C: ViewCell>(&self, cell: &mut C) {
        if let Some(foreground_colour) = self.foreground_colour {
            cell.set_foreground_colour(foreground_colour);
        }
        if let Some(background_colour) = self.background_colour {
            cell.set_background_colour(background_colour);
        }
        cell.set_bold(self.bold);
        cell.set_underline(self.underline);
    }
}