Expand description
Terminal cell values and grapheme segmentation.
This module defines Cell, the value stored by buffers and surfaces.
A cell combines grapheme content, visual style, and a structural role
that describes whether it is a narrow cell, a wide-cell primary, or the
continuation column for a wide primary.
§Cell value type
A Cell stores three pieces of state:
content: the grapheme cluster to display. Continuation cells have no content of their own.style: colors, attributes, underline data, and link metadata applied to the cell.Kind: the structural role that determines the cell’s column footprint.
The cell’s display width is derived from its Kind: narrow cells
occupy one column, wide primaries occupy two columns, and continuation
placeholders report width 0 because their column is owned by the wide
primary to the left.
§Construction
Construct cells with Cell::narrow for one-column graphemes and
Cell::wide for two-column graphemes. Both constructors use the
default Style. Use Cell::style() to attach a
style after construction.
Cell::continuation creates the internal placeholder used for the
second column of a wide grapheme. Most callers should not write
continuations directly; writing a wide cell through
Buffer::set or
SurfaceMut::set_cell creates the
placeholder automatically.
use uncurses::cell::Cell;
let a = Cell::narrow("a");
assert_eq!(a.width(), 1);
let wide = Cell::wide("中");
assert_eq!(wide.width(), 2);§Wide cells
A two-column grapheme occupies two adjacent grid columns. The left column stores the wide primary and the right column stores a continuation placeholder:
col: 0 1 2
┌───────┬───────┬───┐
row 0 │ 中 │ cont. │ A │
└───────┴───────┴───┘
width=2 width=0 width=1Continuations are considered blank by Cell::is_blank because they do
not render independent content. They exist so row storage can preserve
the one-Cell-per-column layout while still representing wide graphemes
accurately.
Structs§
- Cell
- A single terminal-grid cell.
Enums§
- Kind
- Structural role of a cell within a terminal grid.