TerminalText

Output written for a terminal, as a terminal shows it: the control functions of ECMA-48 (ISO/IEC 6429, "ANSI escape codes") in the subset xterm-compatible programs use for their output, applied to a screen of lines with a cursor.

  • C0 controls: \n (new line), \r (back to the start of the line, so progress bars redraw in place), \b (back one column), \t (tab stops every 8 columns); others are dropped.

  • CSI: SGR m (bold, dim, italic, underline, blink as nothing, inverse, conceal, strike, the 16 colors and their bright forms, 256-color 38;5;n and true color 38;2;r;g;b, in ; or : form, foreground and background); erase in line K and in display J; cursor up / down / forward / back A B C D, next / previous line E F, column G, position H / f (rows relative to the first line of the output). Private modes (?25l…) and the rest are ignored.

  • OSC: 8 hyperlinks (OSC 8, as in iTerm2, GNOME Terminal and Windows Terminal) become Style.link; other OSC strings (window titles…) are dropped. Other escape sequences are dropped.

UI elements render lines with their styles; plain is what the terminal would show as text, e.g. for a model, which should not pay for escape codes and redrawn progress bars.

Types

Link copied to clipboard
sealed interface Color

A terminal color: one of the 256 indexed colors (0–15 are the theme's 16) or a 24-bit one.

Link copied to clipboard
object Companion
Link copied to clipboard
data class Span(val text: String, val style: TerminalText.Style)

A run of text with one style.

Link copied to clipboard
data class Style(val foreground: TerminalText.Color? = null, val background: TerminalText.Color? = null, val bold: Boolean = false, val dim: Boolean = false, val italic: Boolean = false, val underline: Boolean = false, val inverse: Boolean = false, val conceal: Boolean = false, val strikethrough: Boolean = false, val link: String? = null)

How text is drawn; null colors are the terminal's defaults.

Properties

Link copied to clipboard

Lines that scrolled out of the kept lines (see parse's maxLines).

Link copied to clipboard

Functions

Link copied to clipboard
fun plain(): String

The text as the terminal shows it, without styles; trailing blanks are trimmed from each line.