Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/prompt_toolkit/styles/defaults.py: 88%
16 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
1"""
2The default styling.
3"""
4from __future__ import annotations
6from prompt_toolkit.cache import memoized
8from .base import ANSI_COLOR_NAMES, BaseStyle
9from .named_colors import NAMED_COLORS
10from .style import Style, merge_styles
12__all__ = [
13 "default_ui_style",
14 "default_pygments_style",
15]
17#: Default styling. Mapping from classnames to their style definition.
18PROMPT_TOOLKIT_STYLE = [
19 # Highlighting of search matches in document.
20 ("search", "bg:ansibrightyellow ansiblack"),
21 ("search.current", ""),
22 # Incremental search.
23 ("incsearch", ""),
24 ("incsearch.current", "reverse"),
25 # Highlighting of select text in document.
26 ("selected", "reverse"),
27 ("cursor-column", "bg:#dddddd"),
28 ("cursor-line", "underline"),
29 ("color-column", "bg:#ccaacc"),
30 # Highlighting of matching brackets.
31 ("matching-bracket", ""),
32 ("matching-bracket.other", "#000000 bg:#aacccc"),
33 ("matching-bracket.cursor", "#ff8888 bg:#880000"),
34 # Styling of other cursors, in case of block editing.
35 ("multiple-cursors", "#000000 bg:#ccccaa"),
36 # Line numbers.
37 ("line-number", "#888888"),
38 ("line-number.current", "bold"),
39 ("tilde", "#8888ff"),
40 # Default prompt.
41 ("prompt", ""),
42 ("prompt.arg", "noinherit"),
43 ("prompt.arg.text", ""),
44 ("prompt.search", "noinherit"),
45 ("prompt.search.text", ""),
46 # Search toolbar.
47 ("search-toolbar", "bold"),
48 ("search-toolbar.text", "nobold"),
49 # System toolbar
50 ("system-toolbar", "bold"),
51 ("system-toolbar.text", "nobold"),
52 # "arg" toolbar.
53 ("arg-toolbar", "bold"),
54 ("arg-toolbar.text", "nobold"),
55 # Validation toolbar.
56 ("validation-toolbar", "bg:#550000 #ffffff"),
57 ("window-too-small", "bg:#550000 #ffffff"),
58 # Completions toolbar.
59 ("completion-toolbar", "bg:#bbbbbb #000000"),
60 ("completion-toolbar.arrow", "bg:#bbbbbb #000000 bold"),
61 ("completion-toolbar.completion", "bg:#bbbbbb #000000"),
62 ("completion-toolbar.completion.current", "bg:#444444 #ffffff"),
63 # Completions menu.
64 ("completion-menu", "bg:#bbbbbb #000000"),
65 ("completion-menu.completion", ""),
66 # (Note: for the current completion, we use 'reverse' on top of fg/bg
67 # colors. This is to have proper rendering with NO_COLOR=1).
68 ("completion-menu.completion.current", "fg:#888888 bg:#ffffff reverse"),
69 ("completion-menu.meta.completion", "bg:#999999 #000000"),
70 ("completion-menu.meta.completion.current", "bg:#aaaaaa #000000"),
71 ("completion-menu.multi-column-meta", "bg:#aaaaaa #000000"),
72 # Fuzzy matches in completion menu (for FuzzyCompleter).
73 ("completion-menu.completion fuzzymatch.outside", "fg:#444444"),
74 ("completion-menu.completion fuzzymatch.inside", "bold"),
75 ("completion-menu.completion fuzzymatch.inside.character", "underline"),
76 ("completion-menu.completion.current fuzzymatch.outside", "fg:default"),
77 ("completion-menu.completion.current fuzzymatch.inside", "nobold"),
78 # Styling of readline-like completions.
79 ("readline-like-completions", ""),
80 ("readline-like-completions.completion", ""),
81 ("readline-like-completions.completion fuzzymatch.outside", "#888888"),
82 ("readline-like-completions.completion fuzzymatch.inside", ""),
83 ("readline-like-completions.completion fuzzymatch.inside.character", "underline"),
84 # Scrollbars.
85 ("scrollbar.background", "bg:#aaaaaa"),
86 ("scrollbar.button", "bg:#444444"),
87 ("scrollbar.arrow", "noinherit bold"),
88 # Start/end of scrollbars. Adding 'underline' here provides a nice little
89 # detail to the progress bar, but it doesn't look good on all terminals.
90 # ('scrollbar.start', 'underline #ffffff'),
91 # ('scrollbar.end', 'underline #000000'),
92 # Auto suggestion text.
93 ("auto-suggestion", "#666666"),
94 # Trailing whitespace and tabs.
95 ("trailing-whitespace", "#999999"),
96 ("tab", "#999999"),
97 # When Control-C/D has been pressed. Grayed.
98 ("aborting", "#888888 bg:default noreverse noitalic nounderline noblink"),
99 ("exiting", "#888888 bg:default noreverse noitalic nounderline noblink"),
100 # Entering a Vi digraph.
101 ("digraph", "#4444ff"),
102 # Control characters, like ^C, ^X.
103 ("control-character", "ansiblue"),
104 # Non-breaking space.
105 ("nbsp", "underline ansiyellow"),
106 # Default styling of HTML elements.
107 ("i", "italic"),
108 ("u", "underline"),
109 ("s", "strike"),
110 ("b", "bold"),
111 ("em", "italic"),
112 ("strong", "bold"),
113 ("del", "strike"),
114 ("hidden", "hidden"),
115 # It should be possible to use the style names in HTML.
116 # <reverse>...</reverse> or <noreverse>...</noreverse>.
117 ("italic", "italic"),
118 ("underline", "underline"),
119 ("strike", "strike"),
120 ("bold", "bold"),
121 ("reverse", "reverse"),
122 ("noitalic", "noitalic"),
123 ("nounderline", "nounderline"),
124 ("nostrike", "nostrike"),
125 ("nobold", "nobold"),
126 ("noreverse", "noreverse"),
127 # Prompt bottom toolbar
128 ("bottom-toolbar", "reverse"),
129]
132# Style that will turn for instance the class 'red' into 'red'.
133COLORS_STYLE = [(name, "fg:" + name) for name in ANSI_COLOR_NAMES] + [
134 (name.lower(), "fg:" + name) for name in NAMED_COLORS
135]
138WIDGETS_STYLE = [
139 # Dialog windows.
140 ("dialog", "bg:#4444ff"),
141 ("dialog.body", "bg:#ffffff #000000"),
142 ("dialog.body text-area", "bg:#cccccc"),
143 ("dialog.body text-area last-line", "underline"),
144 ("dialog frame.label", "#ff0000 bold"),
145 # Scrollbars in dialogs.
146 ("dialog.body scrollbar.background", ""),
147 ("dialog.body scrollbar.button", "bg:#000000"),
148 ("dialog.body scrollbar.arrow", ""),
149 ("dialog.body scrollbar.start", "nounderline"),
150 ("dialog.body scrollbar.end", "nounderline"),
151 # Buttons.
152 ("button", ""),
153 ("button.arrow", "bold"),
154 ("button.focused", "bg:#aa0000 #ffffff"),
155 # Menu bars.
156 ("menu-bar", "bg:#aaaaaa #000000"),
157 ("menu-bar.selected-item", "bg:#ffffff #000000"),
158 ("menu", "bg:#888888 #ffffff"),
159 ("menu.border", "#aaaaaa"),
160 ("menu.border shadow", "#444444"),
161 # Shadows.
162 ("dialog shadow", "bg:#000088"),
163 ("dialog.body shadow", "bg:#aaaaaa"),
164 ("progress-bar", "bg:#000088"),
165 ("progress-bar.used", "bg:#ff0000"),
166]
169# The default Pygments style, include this by default in case a Pygments lexer
170# is used.
171PYGMENTS_DEFAULT_STYLE = {
172 "pygments.whitespace": "#bbbbbb",
173 "pygments.comment": "italic #408080",
174 "pygments.comment.preproc": "noitalic #bc7a00",
175 "pygments.keyword": "bold #008000",
176 "pygments.keyword.pseudo": "nobold",
177 "pygments.keyword.type": "nobold #b00040",
178 "pygments.operator": "#666666",
179 "pygments.operator.word": "bold #aa22ff",
180 "pygments.name.builtin": "#008000",
181 "pygments.name.function": "#0000ff",
182 "pygments.name.class": "bold #0000ff",
183 "pygments.name.namespace": "bold #0000ff",
184 "pygments.name.exception": "bold #d2413a",
185 "pygments.name.variable": "#19177c",
186 "pygments.name.constant": "#880000",
187 "pygments.name.label": "#a0a000",
188 "pygments.name.entity": "bold #999999",
189 "pygments.name.attribute": "#7d9029",
190 "pygments.name.tag": "bold #008000",
191 "pygments.name.decorator": "#aa22ff",
192 # Note: In Pygments, Token.String is an alias for Token.Literal.String,
193 # and Token.Number as an alias for Token.Literal.Number.
194 "pygments.literal.string": "#ba2121",
195 "pygments.literal.string.doc": "italic",
196 "pygments.literal.string.interpol": "bold #bb6688",
197 "pygments.literal.string.escape": "bold #bb6622",
198 "pygments.literal.string.regex": "#bb6688",
199 "pygments.literal.string.symbol": "#19177c",
200 "pygments.literal.string.other": "#008000",
201 "pygments.literal.number": "#666666",
202 "pygments.generic.heading": "bold #000080",
203 "pygments.generic.subheading": "bold #800080",
204 "pygments.generic.deleted": "#a00000",
205 "pygments.generic.inserted": "#00a000",
206 "pygments.generic.error": "#ff0000",
207 "pygments.generic.emph": "italic",
208 "pygments.generic.strong": "bold",
209 "pygments.generic.prompt": "bold #000080",
210 "pygments.generic.output": "#888",
211 "pygments.generic.traceback": "#04d",
212 "pygments.error": "border:#ff0000",
213}
216@memoized()
217def default_ui_style() -> BaseStyle:
218 """
219 Create a default `Style` object.
220 """
221 return merge_styles(
222 [
223 Style(PROMPT_TOOLKIT_STYLE),
224 Style(COLORS_STYLE),
225 Style(WIDGETS_STYLE),
226 ]
227 )
230@memoized()
231def default_pygments_style() -> Style:
232 """
233 Create a `Style` object that contains the default Pygments style.
234 """
235 return Style.from_dict(PYGMENTS_DEFAULT_STYLE)