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