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: StyleVisual 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
impl Cell
Sourcepub const BLANK: Cell
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.
Sourcepub fn narrow(content: impl Into<CompactString>) -> Self
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.
Sourcepub fn wide(content: impl Into<CompactString>) -> Self
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.
Sourcepub fn continuation() -> Self
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.
Sourcepub fn kind(&self) -> Kind
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.
Sourcepub fn is_narrow(&self) -> bool
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.
Sourcepub fn is_wide(&self) -> bool
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.
Sourcepub fn is_continuation(&self) -> bool
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.
Sourcepub fn is_blank(&self) -> bool
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.
Sourcepub fn width(&self) -> u8
pub fn width(&self) -> u8
Column footprint of this cell on the grid.
Narrow→ 1Wide→ 2Continuation→ 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.
Sourcepub fn style(self, style: impl Into<Style>) -> Self
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.