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.2.2, created at 2023-03-26 06:07 +0000

1""" 

2The default styling. 

3""" 

4from __future__ import annotations 

5 

6from prompt_toolkit.cache import memoized 

7 

8from .base import ANSI_COLOR_NAMES, BaseStyle 

9from .named_colors import NAMED_COLORS 

10from .style import Style, merge_styles 

11 

12__all__ = [ 

13 "default_ui_style", 

14 "default_pygments_style", 

15] 

16 

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 ("completion-menu.completion.current", "bg:#888888 #ffffff"), 

67 ("completion-menu.meta.completion", "bg:#999999 #000000"), 

68 ("completion-menu.meta.completion.current", "bg:#aaaaaa #000000"), 

69 ("completion-menu.multi-column-meta", "bg:#aaaaaa #000000"), 

70 # Fuzzy matches in completion menu (for FuzzyCompleter). 

71 ("completion-menu.completion fuzzymatch.outside", "fg:#444444"), 

72 ("completion-menu.completion fuzzymatch.inside", "bold"), 

73 ("completion-menu.completion fuzzymatch.inside.character", "underline"), 

74 ("completion-menu.completion.current fuzzymatch.outside", "fg:default"), 

75 ("completion-menu.completion.current fuzzymatch.inside", "nobold"), 

76 # Styling of readline-like completions. 

77 ("readline-like-completions", ""), 

78 ("readline-like-completions.completion", ""), 

79 ("readline-like-completions.completion fuzzymatch.outside", "#888888"), 

80 ("readline-like-completions.completion fuzzymatch.inside", ""), 

81 ("readline-like-completions.completion fuzzymatch.inside.character", "underline"), 

82 # Scrollbars. 

83 ("scrollbar.background", "bg:#aaaaaa"), 

84 ("scrollbar.button", "bg:#444444"), 

85 ("scrollbar.arrow", "noinherit bold"), 

86 # Start/end of scrollbars. Adding 'underline' here provides a nice little 

87 # detail to the progress bar, but it doesn't look good on all terminals. 

88 # ('scrollbar.start', 'underline #ffffff'), 

89 # ('scrollbar.end', 'underline #000000'), 

90 # Auto suggestion text. 

91 ("auto-suggestion", "#666666"), 

92 # Trailing whitespace and tabs. 

93 ("trailing-whitespace", "#999999"), 

94 ("tab", "#999999"), 

95 # When Control-C/D has been pressed. Grayed. 

96 ("aborting", "#888888 bg:default noreverse noitalic nounderline noblink"), 

97 ("exiting", "#888888 bg:default noreverse noitalic nounderline noblink"), 

98 # Entering a Vi digraph. 

99 ("digraph", "#4444ff"), 

100 # Control characters, like ^C, ^X. 

101 ("control-character", "ansiblue"), 

102 # Non-breaking space. 

103 ("nbsp", "underline ansiyellow"), 

104 # Default styling of HTML elements. 

105 ("i", "italic"), 

106 ("u", "underline"), 

107 ("s", "strike"), 

108 ("b", "bold"), 

109 ("em", "italic"), 

110 ("strong", "bold"), 

111 ("del", "strike"), 

112 ("hidden", "hidden"), 

113 # It should be possible to use the style names in HTML. 

114 # <reverse>...</reverse> or <noreverse>...</noreverse>. 

115 ("italic", "italic"), 

116 ("underline", "underline"), 

117 ("strike", "strike"), 

118 ("bold", "bold"), 

119 ("reverse", "reverse"), 

120 ("noitalic", "noitalic"), 

121 ("nounderline", "nounderline"), 

122 ("nostrike", "nostrike"), 

123 ("nobold", "nobold"), 

124 ("noreverse", "noreverse"), 

125 # Prompt bottom toolbar 

126 ("bottom-toolbar", "reverse"), 

127] 

128 

129 

130# Style that will turn for instance the class 'red' into 'red'. 

131COLORS_STYLE = [(name, "fg:" + name) for name in ANSI_COLOR_NAMES] + [ 

132 (name.lower(), "fg:" + name) for name in NAMED_COLORS 

133] 

134 

135 

136WIDGETS_STYLE = [ 

137 # Dialog windows. 

138 ("dialog", "bg:#4444ff"), 

139 ("dialog.body", "bg:#ffffff #000000"), 

140 ("dialog.body text-area", "bg:#cccccc"), 

141 ("dialog.body text-area last-line", "underline"), 

142 ("dialog frame.label", "#ff0000 bold"), 

143 # Scrollbars in dialogs. 

144 ("dialog.body scrollbar.background", ""), 

145 ("dialog.body scrollbar.button", "bg:#000000"), 

146 ("dialog.body scrollbar.arrow", ""), 

147 ("dialog.body scrollbar.start", "nounderline"), 

148 ("dialog.body scrollbar.end", "nounderline"), 

149 # Buttons. 

150 ("button", ""), 

151 ("button.arrow", "bold"), 

152 ("button.focused", "bg:#aa0000 #ffffff"), 

153 # Menu bars. 

154 ("menu-bar", "bg:#aaaaaa #000000"), 

155 ("menu-bar.selected-item", "bg:#ffffff #000000"), 

156 ("menu", "bg:#888888 #ffffff"), 

157 ("menu.border", "#aaaaaa"), 

158 ("menu.border shadow", "#444444"), 

159 # Shadows. 

160 ("dialog shadow", "bg:#000088"), 

161 ("dialog.body shadow", "bg:#aaaaaa"), 

162 ("progress-bar", "bg:#000088"), 

163 ("progress-bar.used", "bg:#ff0000"), 

164] 

165 

166 

167# The default Pygments style, include this by default in case a Pygments lexer 

168# is used. 

169PYGMENTS_DEFAULT_STYLE = { 

170 "pygments.whitespace": "#bbbbbb", 

171 "pygments.comment": "italic #408080", 

172 "pygments.comment.preproc": "noitalic #bc7a00", 

173 "pygments.keyword": "bold #008000", 

174 "pygments.keyword.pseudo": "nobold", 

175 "pygments.keyword.type": "nobold #b00040", 

176 "pygments.operator": "#666666", 

177 "pygments.operator.word": "bold #aa22ff", 

178 "pygments.name.builtin": "#008000", 

179 "pygments.name.function": "#0000ff", 

180 "pygments.name.class": "bold #0000ff", 

181 "pygments.name.namespace": "bold #0000ff", 

182 "pygments.name.exception": "bold #d2413a", 

183 "pygments.name.variable": "#19177c", 

184 "pygments.name.constant": "#880000", 

185 "pygments.name.label": "#a0a000", 

186 "pygments.name.entity": "bold #999999", 

187 "pygments.name.attribute": "#7d9029", 

188 "pygments.name.tag": "bold #008000", 

189 "pygments.name.decorator": "#aa22ff", 

190 # Note: In Pygments, Token.String is an alias for Token.Literal.String, 

191 # and Token.Number as an alias for Token.Literal.Number. 

192 "pygments.literal.string": "#ba2121", 

193 "pygments.literal.string.doc": "italic", 

194 "pygments.literal.string.interpol": "bold #bb6688", 

195 "pygments.literal.string.escape": "bold #bb6622", 

196 "pygments.literal.string.regex": "#bb6688", 

197 "pygments.literal.string.symbol": "#19177c", 

198 "pygments.literal.string.other": "#008000", 

199 "pygments.literal.number": "#666666", 

200 "pygments.generic.heading": "bold #000080", 

201 "pygments.generic.subheading": "bold #800080", 

202 "pygments.generic.deleted": "#a00000", 

203 "pygments.generic.inserted": "#00a000", 

204 "pygments.generic.error": "#ff0000", 

205 "pygments.generic.emph": "italic", 

206 "pygments.generic.strong": "bold", 

207 "pygments.generic.prompt": "bold #000080", 

208 "pygments.generic.output": "#888", 

209 "pygments.generic.traceback": "#04d", 

210 "pygments.error": "border:#ff0000", 

211} 

212 

213 

214@memoized() 

215def default_ui_style() -> BaseStyle: 

216 """ 

217 Create a default `Style` object. 

218 """ 

219 return merge_styles( 

220 [ 

221 Style(PROMPT_TOOLKIT_STYLE), 

222 Style(COLORS_STYLE), 

223 Style(WIDGETS_STYLE), 

224 ] 

225 ) 

226 

227 

228@memoized() 

229def default_pygments_style() -> Style: 

230 """ 

231 Create a `Style` object that contains the default Pygments style. 

232 """ 

233 return Style.from_dict(PYGMENTS_DEFAULT_STYLE)