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