Skip to content

parseAnsi

function parseAnsi(input): StyledSegment[];

Parse a string with ANSI escape codes into styled segments.

Handles:

  • SGR codes: \x1b[m (colors, bold, italic, etc.)
  • Resets escape sequences to plain text
ParameterTypeDescription
inputstringString potentially containing ANSI escape codes

StyledSegment[]

Array of segments with text and associated style


PropertyType
bg?Color
bold?boolean
dim?boolean
fg?Color
italic?boolean
strikethrough?boolean
underline?boolean

PropertyType
styleAnsiStyle
textstring