aboutsummaryrefslogtreecommitdiffstats
path: root/src/cell.rs
blob: 3d2a9faf94aec1f49e07a29c78d2b6672ec8630f (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#[derive(Clone, Debug, Default)]
pub struct Cell {
    contents: String,
    attrs: crate::attrs::Attrs,
}

impl Cell {
    pub fn new() -> Self {
        Self::default()
    }

    pub(crate) fn set(&mut self, c: String, a: crate::attrs::Attrs) {
        self.contents = c;
        self.attrs = a;
    }

    pub(crate) fn append(&mut self, c: char) {
        self.contents.push(c);
    }

    pub(crate) fn reset(&mut self) {
        self.contents = String::new();
        self.attrs = crate::attrs::Attrs::default();
    }

    pub fn contents(&self) -> &str {
        &self.contents
    }

    pub fn has_contents(&self) -> bool {
        self.contents != ""
    }

    pub fn is_wide(&self) -> bool {
        crate::unicode::str_width(&self.contents) > 1
    }

    pub fn fgcolor(&self) -> crate::color::Color {
        self.attrs.fgcolor
    }

    pub fn bgcolor(&self) -> crate::color::Color {
        self.attrs.bgcolor
    }

    pub fn bold(&self) -> bool {
        self.attrs.bold
    }

    pub fn italic(&self) -> bool {
        self.attrs.italic
    }

    pub fn inverse(&self) -> bool {
        self.attrs.inverse
    }

    pub fn underline(&self) -> bool {
        self.attrs.underline
    }
}