Skip to main content

Cell

Struct Cell 

Source
pub struct Cell {
    pub style: Style,
    /* private fields */
}
Expand description

A single terminal-grid cell.

Cell is the value stored in buffers and surfaces. It contains the grapheme content for a column, the style applied to that content, and a Kind that determines whether the cell is a one-column value, a two-column wide primary, or a continuation placeholder.

Use Cell::narrow and Cell::wide for normal construction. Use Cell::BLANK for an empty styled-as-default space. Continuations are normally produced by the surface write path rather than by application code.

Fields§

§style: Style

Visual style: colors, attributes, underline, and any attached hyperlink. The link inside style is reference-counted so a run of identically-linked cells shares a single allocation without per-cell deep clones.

Implementations§

Source§

impl Cell

Source

pub const BLANK: Cell

A blank narrow cell with default style.

The blank cell stores a single space (" "), uses Style::EMPTY, and has Kind::Narrow.

§Returns

This is a constant value, so use it directly wherever a default blank cell is needed.

§Panics

Never panics.

§Usage notes

Clearing and newly allocated buffers use BLANK. Clone it when an owned value is required.

Source

pub fn narrow(content: impl Into<CompactString>) -> Self

Create a single-column cell with the given grapheme-cluster content and default style.

§Parameters
  • content: grapheme content to store in the cell.
§Returns

A Kind::Narrow cell with width 1 and default style.

§Panics

Never panics.

§Usage notes

This constructor does not validate display width. Call it only for content that should occupy one terminal column; use Cell::wide for two-column graphemes.

Source

pub fn wide(content: impl Into<CompactString>) -> Self

Create the primary cell of a two-column grapheme.

§Parameters
  • content: grapheme content to store in the wide primary.
§Returns

A Kind::Wide cell with width 2 and default style.

§Panics

Never panics.

§Usage notes

When a wide cell is written through the buffer/surface write path, the slot at column + 1 is filled with a Kind::Continuation placeholder automatically. If there is no room for that placeholder at the row’s right edge, Buffer::set stores a blank instead of half a wide grapheme.

Source

pub fn continuation() -> Self

Create a wide-character continuation placeholder.

Continuation cells carry no content; they occupy the right half of a Cell::wide primary at the column to their left.

§Returns

A Kind::Continuation cell with empty content, default style, and width 0.

§Panics

Never panics.

§Usage notes

Most callers should not construct continuations directly. Prefer writing a Cell::wide through a surface so the primary and continuation remain adjacent.

Source

pub fn kind(&self) -> Kind

Return the cell’s structural role.

§Returns

Kind::Narrow, Kind::Wide, or Kind::Continuation.

§Panics

Never panics.

§Usage notes

Use this when matching all roles explicitly. Predicate helpers such as Cell::is_wide are clearer for single-role checks.

Source

pub fn is_narrow(&self) -> bool

Test whether this is a single-column cell.

§Returns

true when Cell::kind is Kind::Narrow.

§Panics

Never panics.

§Usage notes

Blank cells are narrow; continuation cells are not.

Source

pub fn is_wide(&self) -> bool

Test whether this is the primary of a two-column grapheme.

§Returns

true when Cell::kind is Kind::Wide.

§Panics

Never panics.

§Usage notes

In a well-formed surface, a wide cell is followed immediately by a continuation placeholder.

Source

pub fn is_continuation(&self) -> bool

Test whether this is a wide-character continuation placeholder.

§Returns

true when Cell::kind is Kind::Continuation.

§Panics

Never panics.

§Usage notes

Continuations have width 0, no content, and are considered blank.

Source

pub fn is_blank(&self) -> bool

Test whether this cell renders as blank space.

§Returns

true when the content is empty, the content is a single space, or the cell is a continuation placeholder.

§Panics

Never panics.

§Usage notes

Style is not considered. A styled space still counts as blank because this method answers whether the cell has independent textual content.

Source

pub fn content(&self) -> &str

Return the cell’s grapheme-cluster content.

§Returns

The stored content as &str. Continuation cells return an empty string.

§Panics

Never panics.

§Usage notes

This returns the stored content exactly; it does not derive or append the neighboring continuation for wide cells.

Source

pub fn width(&self) -> u8

Column footprint of this cell on the grid.

  • Narrow → 1
  • Wide → 2
  • Continuation → 0 (the second slot of a wide primary)
§Returns

The number of terminal columns owned by this cell’s role.

§Panics

Never panics.

§Usage notes

Row walkers generally advance by cell.width().max(1) after handling continuations, so they make progress even when encountering a continuation placeholder.

Source

pub fn style(self, style: impl Into<Style>) -> Self

Return this cell with a replacement style.

§Parameters
  • style: style to store on the returned cell.
§Returns

self with its style field replaced by style.

§Panics

Never panics.

§Usage notes

This builder-style method preserves content and Kind. Styling a continuation is possible, but continuations do not render independent content.

Trait Implementations§

Source§

impl Clone for Cell

Source§

fn clone(&self) -> Cell

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 PartialEq for Cell

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 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 UnsafeUnpin 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.
§

impl<T> ErasedDestructor for T
where T: 'static,