Show More
@@ -0,0 +1,26 b'' | |||
|
1 | #***************************************************************************** | |
|
2 | # Copyright (C) 2016 The IPython Team <ipython-dev@scipy.org> | |
|
3 | # | |
|
4 | # Distributed under the terms of the BSD License. The full license is in | |
|
5 | # the file COPYING, distributed as part of this software. | |
|
6 | #***************************************************************************** | |
|
7 | from __future__ import absolute_import | |
|
8 | ||
|
9 | """ | |
|
10 | Color managing related utilities | |
|
11 | """ | |
|
12 | ||
|
13 | import pygments | |
|
14 | ||
|
15 | from traitlets.config import Configurable | |
|
16 | from traitlets import Unicode | |
|
17 | ||
|
18 | ||
|
19 | available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux'] | |
|
20 | ||
|
21 | class Colorable(Configurable): | |
|
22 | """ | |
|
23 | A subclass of configurable for all the classes that have a `default_scheme` | |
|
24 | """ | |
|
25 | default_style=Unicode('lightbg', config=True) | |
|
26 |
@@ -42,6 +42,7 b' from IPython.utils.wildcard import list_namespace' | |||
|
42 | 42 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable |
|
43 | 43 | from IPython.utils.py3compat import cast_unicode, string_types, PY3 |
|
44 | 44 | from IPython.utils.signatures import signature |
|
45 | from IPython.utils.colorable import Colorable | |
|
45 | 46 | |
|
46 | 47 | # builtin docstrings to ignore |
|
47 | 48 | _func_call_docstring = types.FunctionType.__call__.__doc__ |
@@ -365,13 +366,15 b' def find_source_lines(obj):' | |||
|
365 | 366 | return lineno |
|
366 | 367 | |
|
367 | 368 | |
|
368 | class Inspector: | |
|
369 | class Inspector(Colorable): | |
|
369 | 370 | def __init__(self, color_table=InspectColors, |
|
370 | 371 | code_color_table=PyColorize.ANSICodeColors, |
|
371 | 372 | scheme='NoColor', |
|
372 |
str_detail_level=0 |
|
|
373 | str_detail_level=0, | |
|
374 | parent=None, config=None): | |
|
375 | super(Inspector, self).__init__(parent=parent, config=config) | |
|
373 | 376 | self.color_table = color_table |
|
374 |
self.parser = PyColorize.Parser( |
|
|
377 | self.parser = PyColorize.Parser(out='str', parent=self, style=scheme) | |
|
375 | 378 | self.format = self.parser.format |
|
376 | 379 | self.str_detail_level = str_detail_level |
|
377 | 380 | self.set_active_scheme(scheme) |
@@ -85,6 +85,7 b' Inheritance diagram:' | |||
|
85 | 85 | # the file COPYING, distributed as part of this software. |
|
86 | 86 | #***************************************************************************** |
|
87 | 87 | |
|
88 | from __future__ import absolute_import | |
|
88 | 89 | from __future__ import unicode_literals |
|
89 | 90 | from __future__ import print_function |
|
90 | 91 | |
@@ -125,6 +126,8 b' from IPython.utils import ulinecache' | |||
|
125 | 126 | from IPython.utils.data import uniq_stable |
|
126 | 127 | from logging import info, error |
|
127 | 128 | |
|
129 | import IPython.utils.colorable as colorable | |
|
130 | ||
|
128 | 131 | # Globals |
|
129 | 132 | # amount of space to put line numbers before verbose tracebacks |
|
130 | 133 | INDENT_SIZE = 8 |
@@ -476,15 +479,16 b' def find_recursion(etype, value, records):' | |||
|
476 | 479 | |
|
477 | 480 | #--------------------------------------------------------------------------- |
|
478 | 481 | # Module classes |
|
479 |
class TBTools( |
|
|
482 | class TBTools(colorable.Colorable): | |
|
480 | 483 | """Basic tools used by all traceback printer classes.""" |
|
481 | 484 | |
|
482 | 485 | # Number of frames to skip when reporting tracebacks |
|
483 | 486 | tb_offset = 0 |
|
484 | 487 | |
|
485 | def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None): | |
|
488 | def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None, config=None): | |
|
486 | 489 | # Whether to call the interactive pdb debugger after printing |
|
487 | 490 | # tracebacks or not |
|
491 | super(TBTools, self).__init__(parent=parent, config=config) | |
|
488 | 492 | self.call_pdb = call_pdb |
|
489 | 493 | |
|
490 | 494 | # Output stream to write to. Note that we store the original value in |
@@ -590,9 +594,9 b' class ListTB(TBTools):' | |||
|
590 | 594 | Because they are meant to be called without a full traceback (only a |
|
591 | 595 | list), instances of this class can't call the interactive pdb debugger.""" |
|
592 | 596 | |
|
593 | def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None): | |
|
597 | def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None): | |
|
594 | 598 | TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb, |
|
595 | ostream=ostream) | |
|
599 | ostream=ostream, parent=parent) | |
|
596 | 600 | |
|
597 | 601 | def __call__(self, etype, value, elist): |
|
598 | 602 | self.ostream.flush() |
@@ -54,6 +54,8 b' except AttributeError:' | |||
|
54 | 54 | from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable |
|
55 | 55 | from IPython.utils.py3compat import PY3 |
|
56 | 56 | |
|
57 | from .colorable import Colorable | |
|
58 | ||
|
57 | 59 | if PY3: |
|
58 | 60 | from io import StringIO |
|
59 | 61 | else: |
@@ -148,15 +150,18 b' LightBGColors = ColorScheme(' | |||
|
148 | 150 | ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors], |
|
149 | 151 | _scheme_default) |
|
150 | 152 | |
|
151 | class Parser: | |
|
153 | class Parser(Colorable): | |
|
152 | 154 | """ Format colored Python source. |
|
153 | 155 | """ |
|
154 | 156 | |
|
155 | def __init__(self, color_table=None,out = sys.stdout): | |
|
157 | def __init__(self, color_table=None, out = sys.stdout, parent=None, style=None): | |
|
156 | 158 | """ Create a parser with a specified color table and output channel. |
|
157 | 159 | |
|
158 | 160 | Call format() to process code. |
|
159 | 161 | """ |
|
162 | ||
|
163 | super(Parser, self).__init__(parent=parent) | |
|
164 | ||
|
160 | 165 | self.color_table = color_table and color_table or ANSICodeColors |
|
161 | 166 | self.out = out |
|
162 | 167 |
General Comments 0
You need to be logged in to leave comments.
Login now