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 the number of
terminal columns the content occupies.
§Cell value type
A Cell stores three pieces of state:
content: the grapheme cluster to display. Continuation cells have no content of their own.- Presentation: visual colors, attributes, underline data, and a shared
hyperlink.
Cell::stylereturns visual fields as a copyableStyle.Cell::linkborrows the separate hyperlink handle. width: the cell’s column footprint, returned byCell::width.
Width also encodes the cell’s structural role. A width of 1 or more
marks a primary cell that owns that many columns. A width of 0 marks a
continuation placeholder, whose column is owned by the primary to its
left.
§Construction
Construct a cell with Cell::new, passing its content and width.
Use Cell::with_style and Cell::with_link to set its presentation.
Measure the width with
WidthMode::grapheme_width
rather than assuming it. Use Style::EMPTY for the default style.
Use Cell::set_style to change the style of an existing cell.
Cell::CONTINUATION is the placeholder that stands in the columns
after a multi-column grapheme. Most callers never write one; writing a
multi-column cell through
Buffer::set or
SurfaceMut::set_cell creates the
placeholders automatically.
use uncurses::cell::Cell;
let a = Cell::new("a", 1);
assert_eq!(a.width(), 1);
let wide = Cell::new("中", 2);
assert_eq!(wide.width(), 2);§Multi-column cells
A grapheme wider than one column occupies that many adjacent grid columns. The leftmost column stores the primary and every column after it stores a continuation placeholder:
col: 0 1 2
┌───────┬───────┬───┐
row 0 │ 中 │ cont. │ A │
└───────┴───────┴───┘
width=2 width=0 width=1Most graphemes are one or two columns wide. A cell may be wider: under
WidthMode::Wc a joined emoji sequence
measures the sum of its code points, so a four-person family emoji is
eight columns and owns seven continuations.
Continuations preserve the one-Cell-per-column layout for wide
graphemes. Cell::is_blank identifies a cell that claims one column
and draws a space, regardless of style. A continuation claims zero
columns, so it returns false.
Structs§
- Cell
- A single terminal-grid cell.