##// END OF EJS Templates
Config options for syntax higlighting style
Thomas Kluyver -
Show More
@@ -1,5 +1,5 b''
1 from IPython.core.interactiveshell import InteractiveShell
1 from IPython.core.interactiveshell import InteractiveShell
2 from traitlets import Bool
2 from traitlets import Bool, Unicode, Dict
3
3
4 from prompt_toolkit.completion import Completer, Completion
4 from prompt_toolkit.completion import Completer, Completion
5 from prompt_toolkit.enums import DEFAULT_BUFFER
5 from prompt_toolkit.enums import DEFAULT_BUFFER
@@ -14,6 +14,7 b' from prompt_toolkit.keys import Keys'
14 from prompt_toolkit.layout.lexers import PygmentsLexer
14 from prompt_toolkit.layout.lexers import PygmentsLexer
15 from prompt_toolkit.styles import PygmentsStyle
15 from prompt_toolkit.styles import PygmentsStyle
16
16
17 from pygments.styles import get_style_by_name
17 from pygments.lexers import Python3Lexer
18 from pygments.lexers import Python3Lexer
18 from pygments.token import Token
19 from pygments.token import Token
19
20
@@ -45,6 +46,14 b' class PTInteractiveShell(InteractiveShell):'
45 help="Use vi style keybindings at the prompt",
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 def get_prompt_tokens(self, cli):
57 def get_prompt_tokens(self, cli):
49 return [
58 return [
50 (Token.Prompt, 'In ['),
59 (Token.Prompt, 'In ['),
@@ -89,13 +98,22 b' class PTInteractiveShell(InteractiveShell):'
89 if cell and (cell != last_cell):
98 if cell and (cell != last_cell):
90 history.append(cell)
99 history.append(cell)
91
100
92 style = PygmentsStyle.from_defaults({
101 style_overrides = {
93 Token.Prompt: '#009900',
102 Token.Prompt: '#009900',
94 Token.PromptNum: '#00ff00 bold',
103 Token.PromptNum: '#00ff00 bold',
95 Token.Number: '#007700',
104 }
96 Token.Operator: 'noinherit',
105 if self.highlighting_style:
97 Token.String: '#BB6622',
106 style_cls = get_style_by_name(self.highlighting_style)
98 })
107 else:
108 style_cls = get_style_by_name('default')
109 style_overrides.update({
110 Token.Number: '#007700',
111 Token.Operator: 'noinherit',
112 Token.String: '#BB6622',
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 app = create_prompt_application(multiline=True,
118 app = create_prompt_application(multiline=True,
101 lexer=PygmentsLexer(Python3Lexer),
119 lexer=PygmentsLexer(Python3Lexer),
General Comments 0
You need to be logged in to leave comments. Login now