Show More
@@ -1,5 +1,5 b'' | |||
|
1 | 1 | from IPython.core.interactiveshell import InteractiveShell |
|
2 | from traitlets import Bool | |
|
2 | from traitlets import Bool, Unicode, Dict | |
|
3 | 3 | |
|
4 | 4 | from prompt_toolkit.completion import Completer, Completion |
|
5 | 5 | from prompt_toolkit.enums import DEFAULT_BUFFER |
@@ -14,6 +14,7 b' from prompt_toolkit.keys import Keys' | |||
|
14 | 14 | from prompt_toolkit.layout.lexers import PygmentsLexer |
|
15 | 15 | from prompt_toolkit.styles import PygmentsStyle |
|
16 | 16 | |
|
17 | from pygments.styles import get_style_by_name | |
|
17 | 18 | from pygments.lexers import Python3Lexer |
|
18 | 19 | from pygments.token import Token |
|
19 | 20 | |
@@ -45,6 +46,14 b' class PTInteractiveShell(InteractiveShell):' | |||
|
45 | 46 | help="Use vi style keybindings at the prompt", |
|
46 | 47 | ) |
|
47 | 48 | |
|
49 | highlighting_style = Unicode('', config=True, | |
|
50 | help="The name of a Pygments style to use for syntax highlighting" | |
|
51 | ) | |
|
52 | ||
|
53 | highlighting_style_overrides = Dict(config=True, | |
|
54 | help="Override highlighting format for specific tokens" | |
|
55 | ) | |
|
56 | ||
|
48 | 57 | def get_prompt_tokens(self, cli): |
|
49 | 58 | return [ |
|
50 | 59 | (Token.Prompt, 'In ['), |
@@ -89,13 +98,22 b' class PTInteractiveShell(InteractiveShell):' | |||
|
89 | 98 | if cell and (cell != last_cell): |
|
90 | 99 | history.append(cell) |
|
91 | 100 | |
|
92 | style = PygmentsStyle.from_defaults({ | |
|
101 | style_overrides = { | |
|
93 | 102 | Token.Prompt: '#009900', |
|
94 | 103 | Token.PromptNum: '#00ff00 bold', |
|
104 | } | |
|
105 | if self.highlighting_style: | |
|
106 | style_cls = get_style_by_name(self.highlighting_style) | |
|
107 | else: | |
|
108 | style_cls = get_style_by_name('default') | |
|
109 | style_overrides.update({ | |
|
95 | 110 | Token.Number: '#007700', |
|
96 | 111 | Token.Operator: 'noinherit', |
|
97 | 112 | Token.String: '#BB6622', |
|
98 | 113 | }) |
|
114 | style_overrides.update(self.highlighting_style_overrides) | |
|
115 | style = PygmentsStyle.from_defaults(pygments_style_cls=style_cls, | |
|
116 | style_dict=style_overrides) | |
|
99 | 117 | |
|
100 | 118 | app = create_prompt_application(multiline=True, |
|
101 | 119 | lexer=PygmentsLexer(Python3Lexer), |
General Comments 0
You need to be logged in to leave comments.
Login now