wijjit.rendering.ansi_adapter.ansi_string_to_cells

wijjit.rendering.ansi_adapter.ansi_string_to_cells(ansi_str)[source]

Parse ANSI escape sequence string and convert to Cell objects.

Parameters:

ansi_str (str) – String potentially containing ANSI escape codes

Returns:

List of Cell objects with parsed styling

Return type:

list of Cell

Notes

This function parses ANSI escape sequences and converts them to Cell objects with appropriate styling attributes. Supports: - Basic colors (30-37, 90-97 for foreground; 40-47, 100-107 for background) - True color RGB (38;2;R;G;B and 48;2;R;G;B) - Text attributes (bold, dim, italic, underline, reverse) - Reset codes

This is a temporary utility for the migration period and will be removed once all elements use cell-based rendering.

Wide characters in the pre-parsed ANSI content are mapped one code point per cell here; unlike the standard wijjit.rendering.paint_context.PaintContext.write_text() path, this bridge does not yet emit continuation cells for width-2 glyphs, so pre-rendered ANSI (e.g. Rich-rendered tables) can still miscolumn wide glyphs. Making this cluster-aware is tracked on the roadmap.

Examples

Parse a simple ANSI string:

>>> cells = ansi_string_to_cells('\x1b[31mRed\x1b[0m')
>>> len(cells)
3
>>> cells[0].char
'R'

Parse text with multiple styles:

>>> cells = ansi_string_to_cells('\x1b[1;31mBold Red\x1b[0m')
>>> cells[0].bold
True