Skip to content

Conversation

alcarney
Copy link

@alcarney alcarney commented Jul 7, 2025

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

There are apparently two ways to "spell" the escape code sequence to set a truecolor value. One way uses semicolon delimiters, while the other uses colon delimiters

image

However, when parsing escape codes using Text.from_ansi, rich only recognises codes that use semicolon delimiters

❯ uv run --with rich python
Python 3.13.5 (main, Jun 26 2025, 21:20:04) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rich.text import Text

>>> Text.from_ansi('\x1b[38;2;255;0;0mred\x1b[0m text')
<text 'red text' [Span(0, 3, Style(color=Color('#ff0000', ColorType.TRUECOLOR, triplet=ColorTriplet(red=255, green=0, blue=0))))] ''>

>>> Text.from_ansi('\x1b[38:2::255:0:0mred\x1b[0m text')
<text 'red text' [] ''>

This PR tweaks the AnsiDecoder so that it converts colons to semicolons, allowing both style of codes to be parsed

@alcarney alcarney marked this pull request as ready for review July 7, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant