1
- from __future__ import unicode_literals
1
+ from typing import Dict
2
2
3
- from prompt_toolkit .styles import Style , merge_styles
3
+ from prompt_toolkit .styles import BaseStyle , Style , merge_styles
4
4
from prompt_toolkit .styles .pygments import style_from_pygments_cls
5
- from prompt_toolkit .utils import is_windows , is_conemu_ansi , is_windows_vt100_supported
6
- from pygments .styles import get_style_by_name , get_all_styles
5
+ from prompt_toolkit .utils import is_conemu_ansi , is_windows , is_windows_vt100_supported
6
+ from pygments .styles import get_all_styles , get_style_by_name
7
7
8
- __all__ = (
9
- 'get_all_code_styles' ,
10
- 'get_all_ui_styles' ,
11
- 'generate_style' ,
12
- )
8
+ __all__ = ["get_all_code_styles" , "get_all_ui_styles" , "generate_style" ]
13
9
14
10
15
- def get_all_code_styles ():
11
+ def get_all_code_styles () -> Dict [ str , BaseStyle ] :
16
12
"""
17
13
Return a mapping from style names to their classes.
18
14
"""
19
- result = dict ((name , style_from_pygments_cls (get_style_by_name (name ))) for name in get_all_styles ())
20
- result ['win32' ] = Style .from_dict (win32_code_style )
15
+ result : Dict [str , BaseStyle ] = {
16
+ name : style_from_pygments_cls (get_style_by_name (name ))
17
+ for name in get_all_styles ()
18
+ }
19
+ result ["win32" ] = Style .from_dict (win32_code_style )
21
20
return result
22
21
23
22
24
- def get_all_ui_styles ():
23
+ def get_all_ui_styles () -> Dict [ str , BaseStyle ] :
25
24
"""
26
25
Return a dict mapping {ui_style_name -> style_dict}.
27
26
"""
28
27
return {
29
- ' default' : Style .from_dict (default_ui_style ),
30
- ' blue' : Style .from_dict (blue_ui_style ),
28
+ " default" : Style .from_dict (default_ui_style ),
29
+ " blue" : Style .from_dict (blue_ui_style ),
31
30
}
32
31
33
32
34
- def generate_style (python_style , ui_style ) :
33
+ def generate_style (python_style : BaseStyle , ui_style : BaseStyle ) -> BaseStyle :
35
34
"""
36
35
Generate Pygments Style class from two dictionaries
37
36
containing style rules.
38
37
"""
39
- return merge_styles ([
40
- python_style ,
41
- ui_style
42
- ])
38
+ return merge_styles ([python_style , ui_style ])
43
39
44
40
45
41
# Code style for Windows consoles. They support only 16 colors,
46
42
# so we choose a combination that displays nicely.
47
43
win32_code_style = {
48
- 'pygments.comment' : "#00ff00" ,
49
- 'pygments.keyword' : '#44ff44' ,
50
- 'pygments.number' : '' ,
51
- 'pygments.operator' : '' ,
52
- 'pygments.string' : '#ff44ff' ,
53
-
54
- 'pygments.name' : '' ,
55
- 'pygments.name.decorator' : '#ff4444' ,
56
- 'pygments.name.class' : '#ff4444' ,
57
- 'pygments.name.function' : '#ff4444' ,
58
- 'pygments.name.builtin' : '#ff4444' ,
59
-
60
- 'pygments.name.attribute' : '' ,
61
- 'pygments.name.constant' : '' ,
62
- 'pygments.name.entity' : '' ,
63
- 'pygments.name.exception' : '' ,
64
- 'pygments.name.label' : '' ,
65
- 'pygments.name.namespace' : '' ,
66
- 'pygments.name.tag' : '' ,
67
- 'pygments.name.variable' : '' ,
44
+ "pygments.comment" : "#00ff00" ,
45
+ "pygments.keyword" : "#44ff44" ,
46
+ "pygments.number" : "" ,
47
+ "pygments.operator" : "" ,
48
+ "pygments.string" : "#ff44ff" ,
49
+ "pygments.name" : "" ,
50
+ "pygments.name.decorator" : "#ff4444" ,
51
+ "pygments.name.class" : "#ff4444" ,
52
+ "pygments.name.function" : "#ff4444" ,
53
+ "pygments.name.builtin" : "#ff4444" ,
54
+ "pygments.name.attribute" : "" ,
55
+ "pygments.name.constant" : "" ,
56
+ "pygments.name.entity" : "" ,
57
+ "pygments.name.exception" : "" ,
58
+ "pygments.name.label" : "" ,
59
+ "pygments.name.namespace" : "" ,
60
+ "pygments.name.tag" : "" ,
61
+ "pygments.name.variable" : "" ,
68
62
}
69
63
70
64
71
65
default_ui_style = {
72
- 'control-character' : 'ansiblue' ,
73
-
66
+ "control-character" : "ansiblue" ,
74
67
# Classic prompt.
75
- 'prompt' : 'bold' ,
76
- 'prompt.dots' : 'noinherit' ,
77
-
68
+ "prompt" : "bold" ,
69
+ "prompt.dots" : "noinherit" ,
78
70
# (IPython <5.0) Prompt: "In [1]:"
79
- 'in' : 'bold #008800' ,
80
- 'in.number' : '' ,
81
-
71
+ "in" : "bold #008800" ,
72
+ "in.number" : "" ,
82
73
# Return value.
83
- 'out' : '#ff0000' ,
84
- 'out.number' : '#ff0000' ,
85
-
74
+ "out" : "#ff0000" ,
75
+ "out.number" : "#ff0000" ,
86
76
# Completions.
87
- 'completion.builtin' : '' ,
88
- 'completion.keyword' : 'fg:#008800' ,
89
-
90
- 'completion.keyword fuzzymatch.inside' : 'fg:#008800' ,
91
- 'completion.keyword fuzzymatch.outside' : 'fg:#44aa44' ,
92
-
77
+ "completion.builtin" : "" ,
78
+ "completion.keyword" : "fg:#008800" ,
79
+ "completion.keyword fuzzymatch.inside" : "fg:#008800" ,
80
+ "completion.keyword fuzzymatch.outside" : "fg:#44aa44" ,
93
81
# Separator between windows. (Used above docstring.)
94
- 'separator' : '#bbbbbb' ,
95
-
82
+ "separator" : "#bbbbbb" ,
96
83
# System toolbar
97
- 'system-toolbar' : '#22aaaa noinherit' ,
98
-
84
+ "system-toolbar" : "#22aaaa noinherit" ,
99
85
# "arg" toolbar.
100
- 'arg-toolbar' : '#22aaaa noinherit' ,
101
- 'arg-toolbar.text' : 'noinherit' ,
102
-
86
+ "arg-toolbar" : "#22aaaa noinherit" ,
87
+ "arg-toolbar.text" : "noinherit" ,
103
88
# Signature toolbar.
104
- 'signature-toolbar' : 'bg:#44bbbb #000000' ,
105
- 'signature-toolbar.currentname' : 'bg:#008888 #ffffff bold' ,
106
- 'signature-toolbar.operator' : '#000000 bold' ,
107
-
108
- 'docstring' : '#888888' ,
109
-
89
+ "signature-toolbar" : "bg:#44bbbb #000000" ,
90
+ "signature-toolbar.currentname" : "bg:#008888 #ffffff bold" ,
91
+ "signature-toolbar.operator" : "#000000 bold" ,
92
+ "docstring" : "#888888" ,
110
93
# Validation toolbar.
111
- 'validation-toolbar' : 'bg:#440000 #aaaaaa' ,
112
-
94
+ "validation-toolbar" : "bg:#440000 #aaaaaa" ,
113
95
# Status toolbar.
114
- 'status-toolbar' : 'bg:#222222 #aaaaaa' ,
115
- 'status-toolbar.title' : 'underline' ,
116
- 'status-toolbar.inputmode' : 'bg:#222222 #ffffaa' ,
117
- 'status-toolbar.key' : 'bg:#000000 #888888' ,
118
- 'status-toolbar.pastemodeon' : 'bg:#aa4444 #ffffff' ,
119
- 'status-toolbar.pythonversion' : 'bg:#222222 #ffffff bold' ,
120
- 'status-toolbar paste-mode-on' : 'bg:#aa4444 #ffffff' ,
121
- 'record' : 'bg:#884444 white' ,
122
- 'status-toolbar.input-mode' : '#ffff44' ,
123
-
96
+ "status-toolbar" : "bg:#222222 #aaaaaa" ,
97
+ "status-toolbar.title" : "underline" ,
98
+ "status-toolbar.inputmode" : "bg:#222222 #ffffaa" ,
99
+ "status-toolbar.key" : "bg:#000000 #888888" ,
100
+ "status-toolbar.pastemodeon" : "bg:#aa4444 #ffffff" ,
101
+ "status-toolbar.pythonversion" : "bg:#222222 #ffffff bold" ,
102
+ "status-toolbar paste-mode-on" : "bg:#aa4444 #ffffff" ,
103
+ "record" : "bg:#884444 white" ,
104
+ "status-toolbar.input-mode" : "#ffff44" ,
124
105
# The options sidebar.
125
- 'sidebar' : 'bg:#bbbbbb #000000' ,
126
- 'sidebar.title' : 'bg:#668866 #ffffff' ,
127
- 'sidebar.label' : 'bg:#bbbbbb #222222' ,
128
- 'sidebar.status' : 'bg:#dddddd #000011' ,
129
- 'sidebar.label selected' : 'bg:#222222 #eeeeee' ,
130
- 'sidebar.status selected' : 'bg:#444444 #ffffff bold' ,
131
-
132
- 'sidebar.separator' : 'underline' ,
133
- 'sidebar.key' : 'bg:#bbddbb #000000 bold' ,
134
- 'sidebar.key.description' : 'bg:#bbbbbb #000000' ,
135
- 'sidebar.helptext' : 'bg:#fdf6e3 #000011' ,
136
-
137
- # # Styling for the history layout.
138
- # history.line: '',
139
- # history.line.selected: 'bg:#008800 #000000',
140
- # history.line.current: 'bg:#ffffff #000000',
141
- # history.line.selected.current: 'bg:#88ff88 #000000',
142
- # history.existinginput: '#888888',
143
-
106
+ "sidebar" : "bg:#bbbbbb #000000" ,
107
+ "sidebar.title" : "bg:#668866 #ffffff" ,
108
+ "sidebar.label" : "bg:#bbbbbb #222222" ,
109
+ "sidebar.status" : "bg:#dddddd #000011" ,
110
+ "sidebar.label selected" : "bg:#222222 #eeeeee" ,
111
+ "sidebar.status selected" : "bg:#444444 #ffffff bold" ,
112
+ "sidebar.separator" : "underline" ,
113
+ "sidebar.key" : "bg:#bbddbb #000000 bold" ,
114
+ "sidebar.key.description" : "bg:#bbbbbb #000000" ,
115
+ "sidebar.helptext" : "bg:#fdf6e3 #000011" ,
116
+ # # Styling for the history layout.
117
+ # history.line: '',
118
+ # history.line.selected: 'bg:#008800 #000000',
119
+ # history.line.current: 'bg:#ffffff #000000',
120
+ # history.line.selected.current: 'bg:#88ff88 #000000',
121
+ # history.existinginput: '#888888',
144
122
# Help Window.
145
- 'window-border' : '#aaaaaa' ,
146
- 'window-title' : 'bg:#bbbbbb #000000' ,
147
-
123
+ "window-border" : "#aaaaaa" ,
124
+ "window-title" : "bg:#bbbbbb #000000" ,
148
125
# Meta-enter message.
149
- 'accept-message' : 'bg:#ffff88 #444444' ,
150
-
126
+ "accept-message" : "bg:#ffff88 #444444" ,
151
127
# Exit confirmation.
152
- ' exit-confirmation' : ' bg:#884444 #ffffff' ,
128
+ " exit-confirmation" : " bg:#884444 #ffffff" ,
153
129
}
154
130
155
131
156
132
# Some changes to get a bit more contrast on Windows consoles.
157
133
# (They only support 16 colors.)
158
134
if is_windows () and not is_conemu_ansi () and not is_windows_vt100_supported ():
159
- default_ui_style .update ({
160
- 'sidebar.title' : 'bg:#00ff00 #ffffff' ,
161
- 'exitconfirmation' : 'bg:#ff4444 #ffffff' ,
162
- 'toolbar.validation' : 'bg:#ff4444 #ffffff' ,
163
-
164
- 'menu.completions.completion' : 'bg:#ffffff #000000' ,
165
- 'menu.completions.completion.current' : 'bg:#aaaaaa #000000' ,
166
- })
135
+ default_ui_style .update (
136
+ {
137
+ "sidebar.title" : "bg:#00ff00 #ffffff" ,
138
+ "exitconfirmation" : "bg:#ff4444 #ffffff" ,
139
+ "toolbar.validation" : "bg:#ff4444 #ffffff" ,
140
+ "menu.completions.completion" : "bg:#ffffff #000000" ,
141
+ "menu.completions.completion.current" : "bg:#aaaaaa #000000" ,
142
+ }
143
+ )
167
144
168
145
169
146
blue_ui_style = {}
170
147
blue_ui_style .update (default_ui_style )
171
- #blue_ui_style.update({
148
+ # blue_ui_style.update({
172
149
# # Line numbers.
173
150
# Token.LineNumber: '#aa6666',
174
151
#
@@ -192,4 +169,4 @@ def generate_style(python_style, ui_style):
192
169
# Token.Menu.Completions.Meta.Current: 'bg:#00aaaa #000000',
193
170
# Token.Menu.Completions.ProgressBar: 'bg:#aaaaaa',
194
171
# Token.Menu.Completions.ProgressButton: 'bg:#000000',
195
- #})
172
+ # })
0 commit comments