Screen class final

One terminal screen: a Surface of cells, painted through canvas, whose changes render turns into the bytes to write to the terminal.

It puts together what a frame needs and keeps them in step: styles and glyphs intern what the cells hold, surface is the frame being painted, and presenter keeps what the terminal shows and writes the difference. TwkApp owns one for its terminal; a screen alone paints and renders without a render tree or a terminal.

A screen 20 cells wide and 2 tall with a line of text, rendered:

final screen = Screen(20, 2);
final pen = screen.styles.pen(const Pen(fg: Color.green));
screen.canvas.text(0, 0, 'Ready', pen);
final bytes = screen.render(); // what to write to the terminal

See also:

Constructors

Screen(int width, int height, {TerminalCaps caps = const TerminalCaps(), TextMode textMode = TextMode.graphemes, int ambiguousWidth = 1, ColorMode colorMode = ColorMode.trueColor, bool inline = false, Viewport? viewport, bool atLineStart = true})
A screen width cells wide and height rows tall, blank.

Properties

canvas ↔ Canvas
The canvas that paints surface.
latefinal
glyphs → GlyphTable
The graphemes of more than one code point the screen's cells hold, interned.
final
hashCode → int
The hash code for this object.
no setterinherited
height → int
How many rows tall the screen is.
no setter
presenter ↔ Presenter
What writes surface's changes as bytes, and keeps what the terminal shows.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
styles → StyleTable
The styles the screen's cells are painted in, interned; StyleTable.pen makes a style of a Pen.
final
surface → Surface
The cells of the frame being painted, which render compares with what the terminal shows.
final
width → int
How many cells wide the screen is.
no setter

Methods

commit(Surface rows, [int from = 0, int? to]) → void
Inline mode: rows [from, to) of rows go to the terminal's history, above the region, with the next render, and are never written again (see Presenter.commit).
keepStylesOf(Surface other) → void
Keeps the styles and glyphs of other's cells in a sweep, as those of the screen's surface: a surface painted with styles and glyphs that is kept from one frame to the next (an inline app's history, written a frame at a time).
leave({bool clear = false}) → Uint8List?
The bytes that hand the screen back when the app ends (a view valid until the next call), or null for none: in the inline mode the region stays and the cursor goes below it, or with clear the region is erased; a fixed viewport stays, or is erased, and the cursor goes back where the app found it (see Presenter.leave).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render() → Uint8List?
Encodes everything painted since the last call. Returns the bytes to write to the terminal (a view valid until the next call), or null when nothing changed. Then sweeps the styles if they are due (sweepIfDue).
resize(int width, int height) → void
Makes the screen width x height cells after the terminal was resized; the surface is cleared, to be painted again whole.
resizeRegion(int height) → void
Inline mode: the region becomes height rows tall. The surface is cleared (repaint everything), but the next render writes only what changed on the terminal, after making room for the rows the region gains or erasing those it loses.
sweepIfDue() → void
Sweeps styles (StyleTable.sweep) when twice as many are in use as after their last sweep, and at least sweepFloor, and glyphs (GlyphTable.sweep) the same: what no cell of the surface (of a surface kept, keepStylesOf, of what keeps cells of either, Surface.keep) and nothing the presenter knows the terminal shows has is freed. As what is in use doubles between two sweeps, a style or a glyph costs its sweep once, and an app of a few hundred is never swept. render calls it.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

sweepFloor ↔ int
The fewest styles, or glyphs, in use the styles, or the glyphs, are swept past; a test's may be fewer.
getter/setter pair