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
62
//! Single terminal cell — the smallest unit of the render buffer.
use compact_str::CompactString;
use crate::style::Style;
/// A single terminal cell containing a character and style.
///
/// Each cell holds one grapheme cluster (stored as a [`CompactString`] for
/// inline storage of short strings — no heap allocation for ≤24 bytes).
/// Wide characters (e.g., CJK) occupy two adjacent cells; the second cell's
/// `symbol` is left empty by the buffer layer.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Cell {
/// The grapheme cluster displayed in this cell. Defaults to a single space.
pub symbol: CompactString,
/// The visual style (colors and modifiers) for this cell.
pub style: Style,
/// Optional OSC 8 hyperlink URL. When set, the terminal renders this cell
/// as a clickable link.
pub hyperlink: Option<CompactString>,
}
impl Default for Cell {
fn default() -> Self {
Self {
symbol: CompactString::const_new(" "),
style: Style::new(),
hyperlink: None,
}
}
}
impl Cell {
/// Replace the cell's symbol with the given string slice.
pub fn set_symbol(&mut self, s: &str) -> &mut Self {
self.symbol.clear();
self.symbol.push_str(s);
self
}
/// Replace the cell's symbol with a single character.
pub fn set_char(&mut self, ch: char) -> &mut Self {
self.symbol.clear();
self.symbol.push(ch);
self
}
/// Set the cell's style.
pub fn set_style(&mut self, style: Style) -> &mut Self {
self.style = style;
self
}
/// Reset the cell to a blank space with default style.
pub fn reset(&mut self) {
self.symbol.clear();
self.symbol.push(' ');
self.style = Style::new();
self.hyperlink = None;
}
}