ANSI
parseAnsi and stripAnsi read a line of terminal output in one linear pass: SGR codes (the 16 colours, 256 colours and truecolor in the semicolon and colon forms, bold, dim, italic, underline, inverse, strikethrough, reset) become styled runs, and every other escape sequence, OSC string (titles, hyperlinks), control character and bidi override is dropped; a carriage return redraws the line. The text comes back as strings, never markup. ansiCssColor maps a terminal colour to theme-aware CSS that clamps its lightness to --ansi-lightness-min and --ansi-lightness-max, for 4.5:1 on muted in light and dark.
Example
- ESC[32m✓ESC[0m built in ESC[1m412msESC[0m✓ built in 412ms
- ESC[31;1mERRORESC[0m ESC[38;5;208mredisESC[0m connect ECONNREFUSEDERROR redis connect ECONNREFUSED
- ESC]8;;https://example.comESC\link textESC]8;;ESC\ and ESC[2Kno cursor moveslink text and no cursor moves
- downloading 10%\rdownloading 100% ESC[38;2;120;180;255mdoneESC[0mdownloading 100% done
Installation
Usage
Use parseAnsi to read terminal output yourself (LogViewer already does): it returns the plain text and styled runs, and ansiCssColor turns a run's colour into theme-aware CSS. stripAnsi gives the text alone, for copying or search.
API reference
This item exports functions and types rather than components.
Other exports
ansiCssColoransiHexapplySgrhasAnsiparseAnsistripAnsitype AnsiColortype AnsiLinetype AnsiSpantype AnsiStyleAccessibility
- ansiCssColor keeps a colour's hue and clamps its lightness to --ansi-lightness-min and --ansi-lightness-max, so every terminal colour holds 4.5:1 on muted in light and dark.
- Bidi overrides and control characters are dropped, so a line can't read differently from what it holds.
Agent actions
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.