Skip to main content

Module ansi

Module ansi 

Source
Expand description

Reading text in ANSI units, and closing the state a cut leaves open.

Escape sequences occupy no terminal columns, so every operation that measures, escapes or cuts styled text splits the text into sequences and the plain runs between them, and most also need the byte offset each unit starts at. ansi_units is that split, and it is meant to be the only one; a hand-written walk anywhere else in the workspace fails the ownership test in standout.

An operation that cuts needs one thing more: the sequence closing what the discarded remainder would have closed. AnsiBalance is that rule. Only SGR sequences carry styling — ESC [ … m and the C1 CSI … m — and their parameters apply in the order written, each opening or closing one attribute group. So a targeted reset (22, 23, 24, 39, 49, …) closes only its own group, ESC [ 31 ; 0 m ends closed, and the extended-colour forms 38/48/58 swallow the parameters spelling the colour out so their zero channels are not read as resets. Whatever is left open closes with one ESC [ 0 m.

Walking and balancing live together because separating them is what leaks colour: a caller walking the text itself has to remember the rule, and one that forgets emits an opener with no reset, dyeing every later line of terminal output.

Structs§

AnsiBalance
AnsiUnit

Functions§

ansi_units
closing_for