Skip to main content

Cell

Struct Cell 

Source
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

Source

pub const EMPTY: Self

An empty cell (space character with default colors).

Source

pub fn new(c: char) -> Self

Create a new cell with a single ASCII character.

§Panics

Panics if the character is not ASCII.

Source

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).

Source

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.

Source

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.

Source

pub const fn wide_continuation() -> Self

Create a wide-character continuation cell.

This is placed after a wide CJK character that takes 2 columns.

Source

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).

Source

pub const fn overflow_index(&self) -> Option<u32>

Get the overflow index if this is an overflow cell.

Source

pub const fn is_overflow(&self) -> bool

Check if this cell uses overflow storage.

Source

pub const fn is_wide_continuation(&self) -> bool

Check if this is a wide-character continuation.

Source

pub const fn display_width(&self) -> u8

Get the display width (0, 1, or 2).

Source

pub const fn fg(&self) -> Rgb

Get the foreground color.

Source

pub const fn bg(&self) -> Rgb

Get the background color.

Source

pub const fn modifiers(&self) -> Modifiers

Get the modifiers.

Source

pub const fn flags(&self) -> CellFlags

Get the flags.

Source

pub const fn set_fg(&mut self, fg: Rgb) -> &mut Self

Set the foreground color.

Source

pub const fn set_bg(&mut self, bg: Rgb) -> &mut Self

Set the background color.

Source

pub const fn set_modifiers(&mut self, modifiers: Modifiers) -> &mut Self

Set the modifiers.

Source

pub const fn with_fg(self, fg: Rgb) -> Self

Set the foreground color (builder pattern).

Source

pub const fn with_bg(self, bg: Rgb) -> Self

Set the background color (builder pattern).

Source

pub const fn with_modifiers(self, modifiers: Modifiers) -> Self

Set the modifiers (builder pattern).

Source

pub const fn reset(&mut self)

Reset the cell to empty (space with default colors).

Trait Implementations§

Source§

impl Clone for Cell

Source§

fn clone(&self) -> Cell

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cell

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for Cell

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Cell

Source§

fn eq(&self, other: &Self) -> bool

Optimized equality check.

We compare in order of most likely difference:

  1. Grapheme bytes (most frequently changing)
  2. Colors (next most common)
  3. Modifiers and flags (rarely differ)
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Cell

Source§

impl Eq for Cell

Auto Trait Implementations§

§

impl Freeze for Cell

§

impl RefUnwindSafe for Cell

§

impl Send for Cell

§

impl Sync for Cell

§

impl Unpin for Cell

§

impl UnwindSafe for Cell

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.