slt/cell.rs
1use crate::style::Style;
2
3/// A single terminal cell containing a character and style.
4///
5/// Each cell holds one grapheme cluster (stored as a `String` to support
6/// multi-byte Unicode) and the [`Style`] to render it with. Wide characters
7/// (e.g., CJK) occupy two adjacent cells; the second cell's `symbol` is left
8/// empty by the buffer layer.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct Cell {
11 /// The grapheme cluster displayed in this cell. Defaults to a single space.
12 pub symbol: String,
13 /// The visual style (colors and modifiers) for this cell.
14 pub style: Style,
15 /// Optional OSC 8 hyperlink URL. When set, the terminal renders this cell
16 /// as a clickable link.
17 pub hyperlink: Option<String>,
18}
19
20impl Default for Cell {
21 fn default() -> Self {
22 Self {
23 symbol: " ".into(),
24 style: Style::new(),
25 hyperlink: None,
26 }
27 }
28}
29
30impl Cell {
31 /// Replace the cell's symbol with the given string slice.
32 pub fn set_symbol(&mut self, s: &str) -> &mut Self {
33 self.symbol.clear();
34 self.symbol.push_str(s);
35 self
36 }
37
38 /// Replace the cell's symbol with a single character.
39 pub fn set_char(&mut self, ch: char) -> &mut Self {
40 self.symbol.clear();
41 self.symbol.push(ch);
42 self
43 }
44
45 /// Set the cell's style.
46 pub fn set_style(&mut self, style: Style) -> &mut Self {
47 self.style = style;
48 self
49 }
50
51 /// Reset the cell to a blank space with default style.
52 pub fn reset(&mut self) {
53 self.symbol.clear();
54 self.symbol.push(' ');
55 self.style = Style::new();
56 self.hyperlink = None;
57 }
58}