Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed extraction of recursive exceptions https://github.com/Textualize/rich/pull/3772
- Fixed padding applied to Syntax https://github.com/Textualize/rich/pull/3782
- Fixed `Panel` title missing the panel background style https://github.com/Textualize/rich/issues/3569
- Fixed parsing of SGR color codes using colons https://github.com/Textualize/rich/pull/3789

### Added

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The following people have contributed to the development of Rich:
- [Robin Bowes](https://github.com/yo61)
- [Dennis Brakhane](https://github.com/brakhane)
- [Darren Burns](https://github.com/darrenburns)
- [Alex Carney](https://github.com/alcarney)
- [Ceyda Cinarel](https://github.com/cceyda)
- [Jim Crist-Harif](https://github.com/jcrist)
- [Ed Davis](https://github.com/davised)
Expand Down
3 changes: 2 additions & 1 deletion rich/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def decode_line(self, line: str) -> Text:
Returns:
Text: A Text instance marked up according to ansi codes.
"""

from_ansi = Color.from_ansi
from_rgb = Color.from_rgb
_Style = Style
Expand All @@ -163,7 +164,7 @@ def decode_line(self, line: str) -> Text:
# Ignore invalid codes, because we want to be lenient
codes = [
min(255, int(_code) if _code else 0)
for _code in sgr.split(";")
for _code in sgr.replace("::", ";").replace(":", ";").split(";")
if _code.isdigit() or _code == ""
]
iter_codes = iter(codes)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_ansi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from rich.ansi import AnsiDecoder
from rich.console import Console
from rich.style import Style
Expand Down Expand Up @@ -70,6 +69,23 @@ def test_decode_issue_2688(ansi_bytes, expected_text):
assert str(text) == expected_text


@pytest.mark.parametrize(
"text,expected",
[
(
"\x1b[38;2;255;0;0mred\x1b[0m text",
Text("red text", spans=[Span(0, 3, Style.parse("#ff0000"))]),
),
(
"\x1b[38:2::255:0:0mred\x1b[0m text",
Text("red text", spans=[Span(0, 3, Style.parse("#ff0000"))]),
),
],
)
def test_decode_sgr_rgb(text, expected):
assert Text.from_ansi(text) == expected


@pytest.mark.parametrize("code", [*"0123456789:;<=>?"])
def test_strip_private_escape_sequences(code):
text = Text.from_ansi(f"\x1b{code}x")
Expand Down