term.border

index · term

Overview

Cell borders: the SGR that puts a thin line on a cell's edge. A border is part of the pen. SGR 51 with a colon mask sets the edges, 54 clears them, 56 and 57 set and clear the colour, and SGR 0 clears all of it.

The mask is a sum of TOP (1), RIGHT (2), BOTTOM (4), LEFT (8) and ROUND (16), the flag that rounds a corner where two edges meet.

Only a terminal that answered term.has_borders() reads these sequences. contour frames every cell on any 51:M, so a caller asks term.supports_borders() before it writes one.

Functions

NameSignature
sgrsgr(mask, colour) -> ansi
offoff() -> ansi
wrapwrap(text, mask, colour) -> row
pen_atpen_at(line, pos) -> ansi

sgr(mask, colour) -> ansi

Build the SGR that sets the pen's border

colour takes what term.color takes: a name, a palette index or {r, g, b}. No colour, "reset" or an unknown name leaves 56 out, so the border draws in the cell's ink. A mask of 0 gives 54, which clears the edges.

off() -> ansi

Build the SGR that clears the pen's edges and the border's colour

wrap(text, mask, colour) -> row

Set a border on every cell of one row of text

Arms the border first, then rewrites each SGR in text to arm it again, since a reset clears it and every tss:apply ends in one. A 51 in text joins mask until a 54 or a reset clears it. So a nested table's top edge and a div's top edge share the row. A 56 in text holds inside that span, and colour comes back after a 57 or a reset. The row closes with off().

text is one row: clip it before the call, since std.txt.limit drops the escapes after its clip point, the close among them.

pen_at(line, pos) -> ansi

Find the border SGR in force at a byte offset of a row

Reads the SGRs that begin before byte pos, as the terminal would. A caller that splices its own SGR into a bordered row, one that ends in a reset, writes the answer after it. Returns "" when no edge is in force.