##// END OF EJS Templates
Check user config to decide whether to use pygments
Alex Hall -
Show More
@@ -97,7 +97,7 b' import time'
97 import traceback
97 import traceback
98
98
99 import stack_data
99 import stack_data
100 from pygments.formatters.terminal import TerminalFormatter
100 from pygments.formatters.terminal256 import Terminal256Formatter
101
101
102 # IPython's own modules
102 # IPython's own modules
103 from IPython import get_ipython
103 from IPython import get_ipython
@@ -129,7 +129,7 b" DEFAULT_SCHEME = 'NoColor'"
129 # (SyntaxErrors have to be treated specially because they have no traceback)
129 # (SyntaxErrors have to be treated specially because they have no traceback)
130
130
131
131
132 def _format_traceback_lines(lines, Colors, lvals):
132 def _format_traceback_lines(lines, Colors, has_colors, lvals):
133 """
133 """
134 Format tracebacks lines with pointing arrow, leading numbers...
134 Format tracebacks lines with pointing arrow, leading numbers...
135
135
@@ -150,7 +150,7 b' def _format_traceback_lines(lines, Colors, lvals):'
150 res.append('%s (...)%s\n' % (Colors.linenoEm, Colors.Normal))
150 res.append('%s (...)%s\n' % (Colors.linenoEm, Colors.Normal))
151 continue
151 continue
152
152
153 line = stack_line.render(pygmented=True).rstrip('\n') + '\n'
153 line = stack_line.render(pygmented=has_colors).rstrip('\n') + '\n'
154 lineno = stack_line.lineno
154 lineno = stack_line.lineno
155 if stack_line.is_current:
155 if stack_line.is_current:
156 # This is the line with the error
156 # This is the line with the error
@@ -246,6 +246,10 b' class TBTools(colorable.Colorable):'
246 message = [[exception_during_handling]]
246 message = [[exception_during_handling]]
247 return message
247 return message
248
248
249 @property
250 def has_colors(self):
251 return self.color_scheme_table.active_scheme_name.lower() != "nocolor"
252
249 def set_colors(self, *args, **kw):
253 def set_colors(self, *args, **kw):
250 """Shorthand access to the color table scheme selector method."""
254 """Shorthand access to the color table scheme selector method."""
251
255
@@ -638,7 +642,7 b' class VerboseTB(TBTools):'
638
642
639 result = '%s %s\n' % (link, call)
643 result = '%s %s\n' % (link, call)
640
644
641 result += ''.join(_format_traceback_lines(frame_info.lines, Colors, lvals))
645 result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals))
642 return result
646 return result
643
647
644 def prepare_header(self, etype, long_version=False):
648 def prepare_header(self, etype, long_version=False):
@@ -709,7 +713,15 b' class VerboseTB(TBTools):'
709 context = number_of_lines_of_context - 1
713 context = number_of_lines_of_context - 1
710 after = context // 2
714 after = context // 2
711 before = context - after
715 before = context - after
712 options = stack_data.Options(before=before, after=after, pygments_formatter=TerminalFormatter())
716 if self.has_colors:
717 formatter = Terminal256Formatter()
718 else:
719 formatter = None
720 options = stack_data.Options(
721 before=before,
722 after=after,
723 pygments_formatter=formatter,
724 )
713 return list(stack_data.FrameInfo.stack_data(etb, options=options))[tb_offset:]
725 return list(stack_data.FrameInfo.stack_data(etb, options=options))[tb_offset:]
714
726
715 def structured_traceback(self, etype, evalue, etb, tb_offset=None,
727 def structured_traceback(self, etype, evalue, etb, tb_offset=None,
General Comments 0
You need to be logged in to leave comments. Login now