pub struct Cell { /* private fields */ }Expand description
A single terminal cell.
This is the atomic unit of display in Flywheel. Each cell contains:
- A grapheme (the character to display)
- Foreground and background colors
- Text modifiers (bold, italic, etc.)
§Memory Layout
The struct is carefully laid out to be exactly 16 bytes:
- 4 bytes for inline grapheme storage
- 2 bytes for grapheme metadata (length + display width)
- 6 bytes for colors (3 bytes fg + 3 bytes bg)
- 1 byte for modifiers
- 1 byte for flags
- 2 bytes padding (power-of-2 alignment)
§Grapheme Handling
Most characters (ASCII, Latin, CJK) fit within the 4-byte inline storage.
For complex graphemes like emoji ZWJ sequences (👨👩👧👦), we set the
OVERFLOW flag and store an index in the grapheme bytes that points
to an external overflow storage.
Implementations§
Source§impl Cell
impl Cell
Sourcepub fn from_char(c: char) -> Self
pub fn from_char(c: char) -> Self
Create a cell from any character.
Returns None if the character’s UTF-8 encoding exceeds 4 bytes
(which never happens for a single char, but may happen for
grapheme clusters when using from_grapheme).
Sourcepub fn from_grapheme(s: &str) -> Option<Self>
pub fn from_grapheme(s: &str) -> Option<Self>
Create a cell from a grapheme string.
If the grapheme fits in 4 bytes, it’s stored inline.
Otherwise, returns None and the caller should use overflow storage.
Sourcepub const fn overflow(index: u32, display_width: u8) -> Self
pub const fn overflow(index: u32, display_width: u8) -> Self
Create an overflow cell with an index to external storage.
The index is stored in the grapheme bytes as a little-endian u32.
Sourcepub const fn wide_continuation() -> Self
pub const fn wide_continuation() -> Self
Create a wide-character continuation cell.
This is placed after a wide CJK character that takes 2 columns.
Sourcepub fn grapheme(&self) -> Option<&str>
pub fn grapheme(&self) -> Option<&str>
Get the grapheme as a string slice.
Returns None if this is an overflow cell (caller should check is_overflow()
and look up the grapheme in the overflow storage).
Sourcepub const fn overflow_index(&self) -> Option<u32>
pub const fn overflow_index(&self) -> Option<u32>
Get the overflow index if this is an overflow cell.
Sourcepub const fn is_overflow(&self) -> bool
pub const fn is_overflow(&self) -> bool
Check if this cell uses overflow storage.
Sourcepub const fn is_wide_continuation(&self) -> bool
pub const fn is_wide_continuation(&self) -> bool
Check if this is a wide-character continuation.
Sourcepub const fn display_width(&self) -> u8
pub const fn display_width(&self) -> u8
Get the display width (0, 1, or 2).
Sourcepub const fn set_modifiers(&mut self, modifiers: Modifiers) -> &mut Self
pub const fn set_modifiers(&mut self, modifiers: Modifiers) -> &mut Self
Set the modifiers.
Sourcepub const fn with_modifiers(self, modifiers: Modifiers) -> Self
pub const fn with_modifiers(self, modifiers: Modifiers) -> Self
Set the modifiers (builder pattern).