Skip to content

Commit 7a24539

Browse files
committed
use a regular expression to remove ansi escapes
1 parent f3b5007 commit 7a24539

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

parse_logs.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,29 @@
1212
from pytest import CollectReport, TestReport
1313

1414
test_collection_stage = "test collection session"
15+
fe_bytes = "[\x40-\x5f]"
16+
parameter_bytes = "[\x30-\x3f]"
17+
intermediate_bytes = "[\x20-\x2f]"
18+
final_bytes = "[\x40-\x7e]"
19+
ansi_fe_escape_re = re.compile(
20+
rf"""
21+
\x1B # ESC
22+
(?:
23+
{fe_bytes} # single-byte Fe
24+
|
25+
\[ # CSI
26+
{parameter_bytes}*
27+
{intermediate_bytes}*
28+
{final_bytes}*
29+
)
30+
""",
31+
re.VERBOSE,
32+
)
1533

1634

1735
def strip_ansi(msg):
18-
pass
36+
"""strip all ansi escape sequences"""
37+
return ansi_fe_escape_re.sub("", msg)
1938

2039

2140
@dataclass

0 commit comments

Comments
 (0)