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 the number of columns the content occupies.

Use Cell::new for construction and 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 one-column cell with default style.

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

§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 const CONTINUATION: Cell

A continuation placeholder with default style.

The placeholder stores no content, uses Style::EMPTY, and has width 0. Cell::is_continuation reports true for it.

§Returns

This is a constant value, so use it directly wherever a continuation is needed.

§Panics

Never panics.

§Usage notes

A wide cell is followed by width - 1 of these, one for every column the cell owns beyond its first. The surface write path lays them down; application code needs them only when it builds a row by hand.

Under background color erase a continuation carries the style of the cell that owns it, so clone the constant and give it that style rather than leaving it default.

Source

pub fn new(content: impl Into<CompactString>, width: u8) -> Self

Create a cell holding content across width terminal columns.

§Parameters
  • content: grapheme content to store in the cell.
  • width: number of terminal columns the content occupies. Width 0 makes a continuation placeholder whatever the content, so use Cell::CONTINUATION when that is what you mean.
§Returns

A cell with the given content and width, and the default style.

§Panics

Never panics.

§Usage notes

This constructor does not validate that width matches the display width of content; the caller chooses the measurement policy. Use WidthMode::grapheme_width to measure, so the stored width matches what the terminal advances.

When a cell wider than one column is written through the buffer/surface write path, the width - 1 slots to its right are filled with continuation placeholders automatically. If there is no room for them at the row’s right edge, Buffer::set stores a blank instead of part of a grapheme.

Source

pub fn is_wide(&self) -> bool

Test whether this cell occupies more than one column.

§Returns

true when Cell::width is 2 or more.

§Panics

Never panics.

§Usage notes

Width alone decides the answer, because width alone decides how many columns the cell takes. A cell that stores no content still owns the columns its width names, and the blank drawn in its place covers all of them.

In a well-formed surface, such a cell is followed immediately by width - 1 continuation placeholders.

Source

pub fn is_continuation(&self) -> bool

Test whether this is a continuation placeholder.

§Returns

true when Cell::width is 0.

§Panics

Never panics.

§Usage notes

Width alone decides, as it does for Cell::is_wide: a cell that claims no column has none to draw in, so whatever it stores is never reached. Width 0, 1, and 2 or more partition every cell into a continuation, a narrow cell, and a wide one.

Source

pub fn is_blank(&self) -> bool

Test whether this cell is a single blank column.

§Returns

true when the cell claims one column and draws a space in it, which is the shape of Cell::BLANK.

§Panics

Never panics.

§Usage notes

Style is not considered. A styled space is still blank, because this method answers what the cell occupies rather than how it is painted.

Width is considered, so the answer stays about one column. A continuation claims none, and a cell claiming several stands for a span rather than a single blank; each is something other than a blank column, and each reports false.

A cell that claims its one column while storing nothing draws a space there, the same as Cell::BLANK, and answers the same way. The question is what reaches the column, so two cells that put the same thing in it give one answer.

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 continuations for multi-column cells.

Source

pub fn width(&self) -> u8

Column footprint of this cell on the grid.

§Returns

The number of terminal columns owned by this cell: 0 for a continuation placeholder, otherwise the width passed to Cell::new.

§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 width. 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 Eq for Cell

Source§

impl PartialEq for Cell

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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
§

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

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.