Show More
@@ -8,10 +8,10 b' from warnings import warn' | |||
|
8 | 8 | |
|
9 | 9 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
10 | 10 | from IPython.utils import io |
|
11 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input | |
|
11 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input, string_types | |
|
12 | 12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
|
13 | 13 | from IPython.utils.process import abbrev_cwd |
|
14 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum | |
|
14 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union | |
|
15 | 15 | |
|
16 | 16 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
|
17 | 17 | from prompt_toolkit.filters import (HasFocus, Condition, IsDone) |
@@ -23,6 +23,7 b' from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatc' | |||
|
23 | 23 | from prompt_toolkit.styles import PygmentsStyle, DynamicStyle |
|
24 | 24 | |
|
25 | 25 | from pygments.styles import get_style_by_name, get_all_styles |
|
26 | from pygments.style import Style | |
|
26 | 27 | from pygments.token import Token |
|
27 | 28 | |
|
28 | 29 | from .debugger import TerminalPdb, Pdb |
@@ -132,8 +133,9 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
132 | 133 | help="Enable mouse support in the prompt" |
|
133 | 134 | ).tag(config=True) |
|
134 | 135 | |
|
135 | highlighting_style = Unicode('legacy', | |
|
136 |
|
|
|
136 | highlighting_style = Union([Unicode('legacy'), Type(klass=Style)], | |
|
137 | help="""The name or class of a Pygments style to use for syntax | |
|
138 | highlighting: \n %s""" % ', '.join(get_all_styles()) | |
|
137 | 139 | ).tag(config=True) |
|
138 | 140 | |
|
139 | 141 | |
@@ -143,7 +145,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
143 | 145 | self.refresh_style() |
|
144 | 146 | |
|
145 | 147 | def refresh_style(self): |
|
146 | self._style = self._make_style_from_name(self.highlighting_style) | |
|
148 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) | |
|
147 | 149 | |
|
148 | 150 | |
|
149 | 151 | highlighting_style_overrides = Dict( |
@@ -229,7 +231,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
229 | 231 | if cell and (cell != last_cell): |
|
230 | 232 | history.append(cell) |
|
231 | 233 | |
|
232 | self._style = self._make_style_from_name(self.highlighting_style) | |
|
234 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) | |
|
233 | 235 | style = DynamicStyle(lambda: self._style) |
|
234 | 236 | |
|
235 | 237 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
@@ -249,14 +251,14 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
249 | 251 | self._pt_app, eventloop=self._eventloop, |
|
250 | 252 | output=create_output(true_color=self.true_color)) |
|
251 | 253 | |
|
252 | def _make_style_from_name(self, name): | |
|
254 | def _make_style_from_name_or_cls(self, name_or_cls): | |
|
253 | 255 | """ |
|
254 | 256 | Small wrapper that make an IPython compatible style from a style name |
|
255 | 257 | |
|
256 | 258 | We need that to add style for prompt ... etc. |
|
257 | 259 | """ |
|
258 | 260 | style_overrides = {} |
|
259 | if name == 'legacy': | |
|
261 | if name_or_cls == 'legacy': | |
|
260 | 262 | legacy = self.colors.lower() |
|
261 | 263 | if legacy == 'linux': |
|
262 | 264 | style_cls = get_style_by_name('monokai') |
@@ -287,7 +289,10 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
287 | 289 | else : |
|
288 | 290 | raise ValueError('Got unknown colors: ', legacy) |
|
289 | 291 | else : |
|
290 | style_cls = get_style_by_name(name) | |
|
292 | if isinstance(name_or_cls, string_types): | |
|
293 | style_cls = get_style_by_name(name_or_cls) | |
|
294 | else: | |
|
295 | style_cls = name_or_cls | |
|
291 | 296 | style_overrides = { |
|
292 | 297 | Token.Prompt: '#009900', |
|
293 | 298 | Token.PromptNum: '#00ff00 bold', |
@@ -101,9 +101,10 b" is set to ``'legacy'``. It has four case-insensitive values:" | |||
|
101 | 101 | should be legible on either dark or light terminal backgrounds. *linux* is |
|
102 | 102 | optimised for dark backgrounds and *lightbg* for light ones. |
|
103 | 103 | |
|
104 |
``TerminalInteractiveShell.highlighting_style`` determines prompt colours and |
|
|
105 |
highlighting. It takes the name |
|
|
106 | value ``'legacy'`` to pick a style in accordance with ``InteractiveShell.colors``. | |
|
104 | ``TerminalInteractiveShell.highlighting_style`` determines prompt colours and | |
|
105 | syntax highlighting. It takes the name (as a string) or class (as a subclass of | |
|
106 | ``pygments.style.Style``) of a Pygments style, or the special value ``'legacy'`` | |
|
107 | to pick a style in accordance with ``InteractiveShell.colors``. | |
|
107 | 108 | |
|
108 | 109 | You can see the Pygments styles available on your system by running:: |
|
109 | 110 |
General Comments 0
You need to be logged in to leave comments.
Login now