Skip to content

Commit 21a18f3

Browse files
Fix parsing of true color in ANSI strings.
1 parent c2c6af8 commit 21a18f3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

prompt_toolkit/formatted_text/ansi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _select_graphic_rendition(self, attrs: List[int]) -> None:
173173
# True colors.
174174
if n == 2 and len(attrs) >= 3:
175175
try:
176-
color_str = "%02x%02x%02x" % (
176+
color_str = "#%02x%02x%02x" % (
177177
attrs.pop(),
178178
attrs.pop(),
179179
attrs.pop(),

tests/test_formatted_text.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def test_ansi_256_color():
9898
]
9999

100100

101+
def test_ansi_true_color():
102+
assert to_formatted_text(ANSI("\033[38;2;144;238;144m$\033[0;39;49m ")) == [
103+
("#90ee90", "$"),
104+
("ansidefault bg:ansidefault", " "),
105+
]
106+
107+
101108
def test_interpolation():
102109
value = Template(" {} ").format(HTML("<b>hello</b>"))
103110

0 commit comments

Comments
 (0)