module

TermBuf::Drawing

Stability: stable — changes only in a major release.

The drawing surface, shared by the terminal and by a batch being built.

The two differ only in what they do with a command: one sends it, the other collects it. Everything else about the API is the same, so it lives here rather than being written twice and drifting apart.

Instance methods

blit(source : Buffer, x : Int32, y : Int32, from : Rect | Nil = nil) : Nil

Copies cells out of source, its top left landing at (x, y), taking from of it or all of it. See Buffer#blit.

The source is read when the command is serviced rather than when it is issued, so a batched blit must not be followed by drawing into the same source before the frame is painted.

Source
clear(style : Style = Style::DEFAULT, blend : Blend | Nil = nil) : Nil

Blanks the whole screen.

Source
fill(rect : Rect, char : Char = ' ', style : Style = Style::DEFAULT, blend : Blend | Nil = nil) : Nil

Sets every cell of rect to char, each cell's style settled by blend against what is already there when there is one.

Source
issue(command : Command) : Nil

Sends command on, or collects it. What a Terminal and a Batcher disagree about, and all they disagree about.

Source
origin

Where this surface's (0, 0) falls in the buffer's coordinates. Zero for everything that draws on a whole buffer; a View says where it sits, so the blend it carries can be asked in its own coordinates.

Source
passthrough(bytes : Bytes) : Nil

Sends bytes to the terminal untouched, after the current frame.

Source
passthrough(text : String) : Nil

Sends bytes to the terminal untouched, after the current frame.

Source
policy

How clusters are measured on this surface, which is what a View cuts writes by. Surfaces that know which buffer they draw into say so.

Source
scroll(rect : Rect, lines : Int32, style : Style = Style::DEFAULT) : Nil

Scrolls rect by lines rows, positive moving content up.

Source
scroll_region(region : Region, lines : Int32, style : Style = Style::DEFAULT) : Nil

Scrolls a region, keeping what leaves the top if it has scrollback.

Source
view(rect : Rect, style : Style = Style::DEFAULT, blend : Blend | Nil = nil) : View

A rectangle of this surface, addressed from its own top left and cut at its own edges. Anything drawn through it merges onto style. See View.

A blend settles the style of every cell drawn through the view, on top of whatever a draw call brings of its own. It is asked in the view's coordinates, (0, 0) at the view's top left, so a Gradient built against the view's bounds lands where the view is — unlike the blend of a draw call, which is asked in the buffer's. See View#blend.

ramp = Gradient.new(top, bottom, Rect.new(0, 0, rect.width, rect.height), :vertical)
screen.view(rect, blend: ramp.background).clear
Source
write(x : Int32, y : Int32, text : String, style : Style = Style::DEFAULT, blend : Blend | Nil = nil) : Nil

Writes text starting at (x, y), one grapheme cluster per cell, stopping at the right edge of the row.

With a blend, each cell gets the style the blend answers for it from what is already there and styleStyle::KEEP_BACKGROUND for a label across a progress bar. See Buffer#write and Blend.

Source
write_char(x : Int32, y : Int32, char : Char, style : Style = Style::DEFAULT, blend : Blend | Nil = nil) : Nil

Writes one character at (x, y), settled by blend against what is already in the cell when there is one.

Source