Skip to content

Commit 0619fb1

Browse files
committed
fixes #693
1 parent 7f175fa commit 0619fb1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fastcore/ansi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
_ANSI_COLORS = ( "ansi-black", "ansi-red", "ansi-green", "ansi-yellow", "ansi-blue", "ansi-magenta", "ansi-cyan", "ansi-white", "ansi-black-intense",
1313
"ansi-red-intense", "ansi-green-intense", "ansi-yellow-intense", "ansi-blue-intense", "ansi-magenta-intense", "ansi-cyan-intense", "ansi-white-intense")
1414

15+
def strip_terminal_queries(text):
16+
# Remove OSC sequences (like background color queries)
17+
text = re.sub(r'\x1b\][^\\x07]*\x07', '', text)
18+
# Remove DSR sequences (device status reports)
19+
return re.sub(r'\x1b\[[0-9]*n', '', text)
20+
1521

1622
def strip_ansi(source):
1723
"Remove ANSI escape codes from text."
@@ -20,7 +26,7 @@ def strip_ansi(source):
2026

2127
def ansi2html(text):
2228
"Convert ANSI colors to HTML colors."
23-
text = escape(text)
29+
text = escape(strip_terminal_queries(text))
2430
return _ansi2anything(text, _htmlconverter)
2531

2632

0 commit comments

Comments
 (0)