class

TermBuf::Sink

Inherits Reference < Object

Stability: stable — changes only in a major release.

One output of a Buffer: what that output is believed to be showing, what it has yet to be told, and the painter and encoder that tell it.

The buffer holds the cells an application drew. Everything about where they go lives here, so a second output — a web terminal, a recording, a second window — is a second sink over the same buffer rather than a second buffer kept in step with the first. Two sinks paint at different moments and know different things about what their terminals can do, which is why the front grid, the damage, the painter and the encoder all come in pairs with them.

A sink holds no IO. It turns a buffer into bytes; carrying them to a device is the driver's job.

buffer = TermBuf::Buffer.new 80, 24
sink = TermBuf::Sink.new buffer, TermBuf::Capabilities::XTERM

buffer.write 0, 0, "hello"
bytes = sink.encoder.encode sink.paint
sink.commit

Constants

UNKNOWN = Cell.new('￿', StyleTable::DEFAULT, 1_u8)

What the cell a forced repaint leaves in the front grid holds: a character no buffer can contain, so every cell compares unequal and the next paint rewrites the screen.

Constructors

new(buffer : Buffer, capabilities : Capabilities)

An output of buffer for a terminal that can do capabilities, attached to the buffer as it is made. A sink over a buffer that already holds content knows nothing about the screen in front of it, so call #invalidate before the first paint.

Source

Instance methods

buffer

The screen this sink paints.

Source
capabilities

What this sink's terminal can do.

Source
capabilities=(capabilities : Capabilities) : Capabilities

Replaces what this sink may use. The next paint should be forced, since what is on the terminal was drawn under the old mask.

Source
clear_overhang=(value : Bool) : Bool

Whether to write the cell after a glyph that may have painted outside its own columns. See Painter#clear_overhang?.

Source
clear_overhang?

Whether to write the cell after a glyph that may have painted outside its own columns. See Painter#clear_overhang?.

Source
commit

Brings the front grid up to date after a paint has been written out, and clears the damage and the scroll hints it was built from.

Source
consumed_serial

The serial of the newest scroll hint this sink has read. See ScrollHint#serial.

Source
damage

What this sink has yet to paint. Its own, because a sink committing must not tell another sink over the same buffer that its rows are clean.

Source
detach

Stops painting the buffer. A detached sink keeps what it was showing but is told nothing further.

Source
dirty?

Whether this sink has anything to paint.

Source
encoder

Turns those operations into bytes for this terminal.

Source
front

What this sink's terminal is believed to be showing.

Source
hardware_cursor

Where to leave the terminal's own cursor when the frame ends, or nil to leave it hidden. See Painter#hardware_cursor.

Source
hardware_cursor=(position : Tuple(Int32, Int32) | Nil) : Tuple(Int32, Int32) | Nil

Where to leave the terminal's own cursor when the frame ends, or nil to leave it hidden. See Painter#hardware_cursor.

Source
invalidate

Forgets what this terminal was showing, so the next paint rewrites every cell. Any scroll hint goes with it: a screen being redrawn outright has nothing to scroll.

Source
paint(forced : Bool = false) : Array(Op)

The operations that bring this sink's terminal up to date. Empty when there is nothing to do. The caller encodes them, writes them out, and then calls #commit.

forced throws away what the terminal was believed to be showing first, so the frame rewrites every cell.

Source
painted?

Whether the front grid holds what the application drew, which is to say a paint would emit no cells.

Source
painter

Works out the operations. One per sink: the decisions it makes turn on the capability mask and on what this front grid holds.

Source
reset_state

Forgets what the terminal was last told about its cursor and style, so the next frame says both again.

Source
resize(columns : Int32, rows : Int32, blank : Cell = Cell.blank) : Nil

Follows the buffer to a new size. Called by Buffer#resize, which has already resized the back grid and this sink's damage with it.

Source
take_composed_drift

The cluster this terminal was found to misplace, and forgets it. See Painter#take_composed_drift.

Source
take_scroll_hints

The scroll hints this sink has not read yet, oldest first. Reading them is what lets the buffer forget them.

Source
watch_composed_drift=(value : Bool) : Bool

Whether to watch for a cluster this terminal will put in the wrong place. See Painter#watch_composed_drift?.

Source
watch_composed_drift?

Whether to watch for a cluster this terminal will put in the wrong place. See Painter#watch_composed_drift?.

Source