@@ -162,21 +162,45 @@ def get_problem_stack(backtrace):
162
162
return "\n " .join (stack )
163
163
164
164
165
+ BT_COLORS = {
166
+ "function_name" : "[[c:cyan]]" ,
167
+ "function_arg" : "[[c:green]]" ,
168
+ "stack_frame" : "[[c:red]]" ,
169
+ "thread_prefix" : "[[c:light-cyan]]" ,
170
+ "thread_id" : "[[c:red]]" ,
171
+ "file_path" : "[[c:light-grey]]" ,
172
+ "line_num" : "[[c:magenta]]" ,
173
+ "address" : "[[c:light-grey]]" ,
174
+ }
175
+
176
+
165
177
# XXX
166
- def colorize_backtrace (text ):
178
+ def colorize_backtrace (text , c = None ):
179
+ if c is None :
180
+ c = BT_COLORS
181
+
167
182
filters = [
168
183
# Function names and the class they belong to
169
- (re .compile (r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()" , flags = re .MULTILINE ), r"\1[[c:cyan]]\2[[rst]]\3" ),
184
+ (
185
+ re .compile (r"^(#[0-9]+ .*?)([a-zA-Z0-9_:\.@]+)(\s?\()" , flags = re .MULTILINE ),
186
+ r"\1" + c ['function_name' ] + r"\2[[rst]]\3" ,
187
+ ),
170
188
# Function argument names
171
- (re .compile (r"([a-zA-Z0-9_#]*)(\s?=\s?)" ), r"[[c:green]] \1[[rst]]\2" ),
189
+ (re .compile (r"([a-zA-Z0-9_#]*)(\s?=\s?)" ), c [ "function_arg" ] + r" \1[[rst]]\2" ),
172
190
# Stack frame number
173
- (re .compile (r"^(#[0-9]+)" , flags = re .MULTILINE ), r"[[c:red]] \1[[rst]]" ),
191
+ (re .compile (r"^(#[0-9]+)" , flags = re .MULTILINE ), c [ "stack_frame" ] + r" \1[[rst]]" ),
174
192
# Thread id colorization
175
- (re .compile (r"^([ \*]) ([0-9]+)" , flags = re .MULTILINE ), r"[[c:light-cyan]]\1 [[c:red]]\2[[rst]]" ),
193
+ (
194
+ re .compile (r"^([ \*]) ([0-9]+)" , flags = re .MULTILINE ),
195
+ c ["thread_prefix" ] + r"\1 " + c ["thread_id" ] + r"\2[[rst]]" ,
196
+ ),
176
197
# File path and line number
177
- (re .compile (r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$" , flags = re .MULTILINE ), r"[[c:light-grey]]\1[[rst]]:[[c:magenta]]\2[[rst]]" ),
198
+ (
199
+ re .compile (r"(\.*[/A-Za-z0-9\+_\.\-]*):(([0-9]+)(:[0-9]+)?)$" , flags = re .MULTILINE ),
200
+ c ["file_path" ] + r"\1[[rst]]:" + c ["line_num" ] + r"\2[[rst]]" ,
201
+ ),
178
202
# Addresses
179
- (re .compile (r"\b(0x[a-f0-9]{6,})\b" ), r"[[c:light-grey]] \1[[rst]]" ),
203
+ (re .compile (r"\b(0x[a-f0-9]{6,})\b" ), c [ "address" ] + r" \1[[rst]]" ),
180
204
]
181
205
182
206
text = six .ensure_str (text )
0 commit comments