struct

TermBuf::Cell

Inherits Struct < Value < Object

Stability: internal

One cell of the terminal grid.

Sixteen bytes, fixed size, with no reference to anything on the heap, so a Grid is one flat Slice(Cell) and a row is a Slice view into it.

A cluster wider than a column occupies several cells: the first carries the character with width set to how many columns it takes, and the rest are continuations with width zero. No part of one is ever written without the others; Grid enforces that.

Constants

MAX_WIDTH = 4

The most columns one grapheme cluster may occupy: a lead and up to three continuations.

Two is what a cluster costs almost everywhere, and the buffer was built for a pair. iTerm2 3.6.11 advances three for a Devanagari conjunct carrying a spacing vowel sign, so a pair is not enough — see Unicode::WidthPolicy#conjunct_spacing_adds?. Four leaves room above the widest reading anyone has measured without letting a bad measurement run away with a row.

Constructors

blank(style : StyleId = StyleTable::DEFAULT) : Cell

An empty cell carrying style, which is what a cleared or scrolled-away part of the screen holds.

Source
continuation(style : StyleId = StyleTable::DEFAULT) : Cell

A cell continuing the cluster to its left.

Source
new(char : Char, style : StyleId = StyleTable::DEFAULT, width : UInt8 = 1_u8, cluster : UInt32 = ClusterPool::NONE)
Source

Instance methods

blank?

Whether the cell holds a space and nothing else, ignoring its style.

Source
char

The cell's character, or '\0' when this cell continues a wide one. When cluster is set, this is the cluster's first code point and the full text lives in the pool.

Source
cluster

ClusterPool id for a multi code point grapheme cluster, or ClusterPool::NONE when char says everything.

Source
continuation?

Whether this cell continues the cluster to its left.

Source
overhangs?

Whether this cell's glyph may paint outside the columns it was given.

Measured rather than reasoned about. A cluster's ink runs past its own columns often enough to matter: is charged one column and painted across three, an uncomposed 👨‍👩 is charged two and painted across four, and neither terminal measured repaints the cell it draws over. Every case seen was non-ASCII and no ASCII character in four runs painted outside its cell, which is what keeps the repaint off ordinary text.

Source
style

Id into the buffer's StyleTable.

Source
text(pool : ClusterPool) : String

The text this cell paints, resolving a cluster id through pool. Falls back to the base character if pool does not know the cluster, so that rendering a grid against the wrong pool degrades rather than raising.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
wide?

Whether this cell leads a cluster taking more than its own column.

Source
width

Cells this character occupies: zero for a continuation, one for a narrow character, and up to MAX_WIDTH for a cluster the terminal advances further for.

Source