Skip to main content

vtcode_ghostty_core/
cell.rs

1use crate::style::Style;
2
3/// A single terminal grid cell.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct Cell {
6    pub(crate) ch: char,
7    pub(crate) style: Style,
8    pub(crate) wide_continuation: bool,
9}
10
11impl Cell {
12    /// Create a blank cell with the given style.
13    pub(crate) fn blank(style: Style) -> Self {
14        Self {
15            ch: ' ',
16            style,
17            wide_continuation: false,
18        }
19    }
20
21    /// Create a printable cell.
22    pub(crate) fn printable(ch: char, style: Style) -> Self {
23        Self {
24            ch,
25            style,
26            wide_continuation: false,
27        }
28    }
29
30    /// Create a wide-character continuation cell (the right-hand half).
31    pub(crate) fn wide_continuation(style: Style) -> Self {
32        Self {
33            ch: ' ',
34            style,
35            wide_continuation: true,
36        }
37    }
38
39    /// The character in this cell.
40    pub fn ch(&self) -> char {
41        self.ch
42    }
43
44    /// The style of this cell.
45    pub fn style(&self) -> &Style {
46        &self.style
47    }
48
49    /// Whether this cell is the right-hand half of a wide character.
50    pub fn is_wide_continuation(&self) -> bool {
51        self.wide_continuation
52    }
53
54    /// Whether this cell is blank (space, not a wide continuation).
55    pub fn is_blank(&self) -> bool {
56        self.ch == ' ' && !self.wide_continuation
57    }
58}