StyleTable class final
Interned cell styles (style id StyleId.base = all defaults) and registered pens.
A cell holds a style id: its colors, attributes and link, each set of them interned once (style). A canvas paints with pen ids (pen), which compose turns, with the style of the cell painted over, into the cell's new style, blending colors with alpha with the cell's and the terminal's default colors (defaultBackgroundRgb, defaultForegroundRgb, paletteRgb). The presenter writes a style's SGR sequence (sgrFromReset, transition) in colorMode.
All lookups on the paint and encode paths are open-addressing probes into typed arrays: no allocation once the working set of styles is known.
A pen is the table's for good. A style is until the table is swept (sweep): the styles no cell has then are freed and their ids given out again, so that a table of ever new colors (a video in a terminal view) holds those on screen, not every one there ever was. What keeps style ids from one frame to the next, beyond the cells the sweep is told of, makes them again when sweeps has changed.
final styles = StyleTable(colorMode: ColorMode.ansi256);
final warning = styles.pen(const Pen(fg: Color.yellow, attrs: Attr.bold));
final cell = styles.compose(StyleId.base, warning); // over a default cell
print(styles.attrsOf(cell) & Attr.bold != 0); // true
See also:
- Screen.styles, the table of a screen, whose canvas paints with its pens.
Constructors
- StyleTable({ColorMode colorMode = ColorMode.trueColor, bool styledUnderlines = true, int defaultBg = 0})
- A table with only style 0, all defaults, and no pens.
Properties
- colorMode ↔ ColorMode
-
The colors the terminal shows: a color it can't is written as the
nearest it can.
getter/setter pair
- defaultBackgroundRgb ↔ int
-
RGB the terminal's default background is assumed to have (for alpha
blending over "default"). Can be filled from an OSC 11 query.
getter/setter pair
- defaultForegroundRgb ↔ int?
-
RGB of the terminal's default text color (OSC 10), for blending
default-colored text with alpha; while it is unknown (null) such text
stays default.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
How many style ids there are: they are 0 to one less, those sweep
freed among them until given out again.
no setter
- live → int
-
How many styles are in use: length less those sweep freed.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- styledUnderlines → bool
-
Whether the terminal shows the underline styles (SGR
4:2to4:5,TerminalCaps.styledUnderlines); false writes each as a plain underline (4), and no underline color (SGR 58), whose colon form such a terminal misreads too; a blank under such an underline keeps the text's color for it, as the text does.no setter - sweeps → int
-
How many times sweep ran: an id kept from before it may be another
style's now.
no setter
Methods
-
attrsOf(
StyleId id) → int -
The attributes of style
id, bits of Attr. -
bgOf(
StyleId id) → Color -
The background color of style
id. -
blankStyleOf(
StyleId style) → StyleId -
The style a blank cell of style
stylelooks like: only the background and the attributes visible on a space matter, plus fg under reverse video and when it colours a line drawn on the space (strike-through, overline, an underline without its own colour). Two blanks with the same blank style are indistinguishable, so the presenter neither rewrites nor switches SGR for them. -
compose(
StyleId style, int penId) → StyleId -
Style that results from painting with
penIdover a cell ofstyle. -
erasable(
StyleId id) → bool - A blank of this style can be produced by an erase (EL/ECH/ED/ICH/ DCH/SU): nothing visible on a space and no hyperlink.
-
fgOf(
StyleId id) → Color -
The text color of style
id. -
linkId(
String uri) → int - Id of a hyperlink target (0 = no link).
-
linkIdOf(
StyleId id) → int -
The link id of style
id(linkId); 0 for none. -
linkOf(
StyleId id) → String? -
The hyperlink target of style
id, or null for none. -
linkUri(
int linkId) → String -
The hyperlink target of
linkId(linkId); empty for 0. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
opaqueStyleOf(
int penId) → StyleId - The resolved style id a pen always produces, or StyleId.none when the result depends on the cell underneath (inherited or translucent colors).
-
paletteRgb(
int index) → int -
RGB palette entry
index(0..255) is blended as: the terminal's own where it told it (OSC 4, setPaletteRgb), xterm's otherwise. -
pen(
Pen pen) → int -
Registers
penand returns its id (stable for the table's lifetime). -
penOf(
int id) → Pen -
The pen registered as
id(pen). -
rgbOf(
Color color, {bool text = false}) → int? -
The RGB (0xRRGGBB)
colorshows as: its own; a palette entry's as paletteRgb has it; the default background's (defaultBackgroundRgb), or withtextthe default text color's (defaultForegroundRgb), null where the terminal has not told it. What a color is mixed from, a fade or a tint over cells of any color. -
setPaletteRgb(
int index, int? rgb) → void -
The terminal shows palette entry
index(0..255) asrgb(0xRRGGBB, from an OSC 4 query); null puts back xterm's. Colors with alpha over or under that entry are blended with it from then on. -
sgrFromReset(
StyleId id) → Uint8List -
Full SGR sequence for
idstarting from a reset state (ESC[0;...m). -
style(
{Color fg = Color.defaultColor, Color bg = Color.defaultColor, int attrs = 0, Color underlineColor = Color.defaultColor, String? link}) → StyleId -
The id of the style of
fgtext overbgwithattrs, an underline ofunderlineColorandlink, interned: the same id for the same values. All left out, it is 0. -
sweep(
void roots(void mark(StyleId id))) → void -
Frees the styles
rootsmarks none of (it is called with the mark), style 0 and the styles of pens (opaqueStyleOf) kept: their ids are given out again, before new ones. The caches by style id are cleared, to be filled again as styles are asked for. -
toString(
) → String -
A string representation of this object.
inherited
-
transition(
StyleId from, StyleId to) → Uint8List -
Shortest SGR sequence that turns terminal state
fromintoto. Cached per pair, so steady-state rendering never builds strings. -
underlineColorOf(
StyleId id) → Color -
The underline color of style
id; the default color for the text's.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited