Skip to content

Fix parsing of RGB codes that use colon delimiters #3789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 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