@@ -41,8 +41,22 @@ class SageSphinxLogger():
41
41
This implements the file object interface to serve as
42
42
``sys.stdout``/``sys.stderr`` replacement.
43
43
"""
44
- ansi_color = re .compile (r'\x1b\[[0-9;]*m' )
45
- ansi_reset = re .compile (r'\x1b\[39;49;00m' )
44
+ # https://en.wikipedia.org/wiki/ANSI_escape_code
45
+ ansi_escape_sequence = re .compile (r'''
46
+ \x1b # ESC
47
+ \[ # CSI sequence starts
48
+ [0-?]* # parameter bytes
49
+ [ -/]* # intermediate bytes
50
+ [@-~] # final byte
51
+ ''' , re .VERBOSE )
52
+ ansi_escape_sequence_color = re .compile (r'''
53
+ \x1b # ESC
54
+ \[ # CSI sequence starts
55
+ [0-9;]* # parameter bytes
56
+ # intermediate bytes
57
+ m # final byte
58
+ ''' , re .VERBOSE )
59
+
46
60
prefix_len = 9
47
61
48
62
def __init__ (self , stream , prefix ):
@@ -164,7 +178,7 @@ def _filter_out(self, line):
164
178
if self ._error is not None and self ._is_stdout :
165
179
# swallow non-errors after an error occurred
166
180
return True
167
- line = re .sub (self .ansi_color , '' , line )
181
+ line = re .sub (self .ansi_escape_sequence , '' , line )
168
182
line = line .strip ()
169
183
for regex in self ._useless_chatter :
170
184
if regex .search (line ) is not None :
@@ -233,7 +247,7 @@ def _log_line(self, line):
233
247
line = old .sub (new , line )
234
248
line = self ._prefix + ' ' + line .rstrip () + '\n '
235
249
if not self ._color :
236
- line = self .ansi_color .sub ('' , line )
250
+ line = self .ansi_escape_sequence_color .sub ('' , line )
237
251
if not skip_this_line :
238
252
# sphinx does produce messages in the current locals which
239
253
# could be non-ascii
0 commit comments