Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/prompt_toolkit/styles/defaults.py: 88%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

1""" 

2The default styling. 

3""" 

4 

5from __future__ import annotations 

6 

7from prompt_toolkit.cache import memoized 

8 

9from .base import ANSI_COLOR_NAMES, BaseStyle 

10from .named_colors import NAMED_COLORS 

11from .style import Style, merge_styles 

12 

13__all__ = [ 

14 "default_ui_style", 

15 "default_pygments_style", 

16] 

17 

18#: Default styling. Mapping from classnames to their style definition. 

19PROMPT_TOOLKIT_STYLE = [ 

20 # Highlighting of search matches in document. 

21 ("search", "bg:ansibrightyellow ansiblack"), 

22 ("search.current", ""), 

23 # Incremental search. 

24 ("incsearch", ""), 

25 ("incsearch.current", "reverse"), 

26 # Highlighting of select text in document. 

27 ("selected", "reverse"), 

28 ("cursor-column", "bg:#dddddd"), 

29 ("cursor-line", "underline"), 

30 ("color-column", "bg:#ccaacc"), 

31 # Highlighting of matching brackets. 

32 ("matching-bracket", ""), 

33 ("matching-bracket.other", "#000000 bg:#aacccc"), 

34 ("matching-bracket.cursor", "#ff8888 bg:#880000"), 

35 # Styling of other cursors, in case of block editing. 

36 ("multiple-cursors", "#000000 bg:#ccccaa"), 

37 # Line numbers. 

38 ("line-number", "#888888"), 

39 ("line-number.current", "bold"), 

40 ("tilde", "#8888ff"), 

41 # Default prompt. 

42 ("prompt", ""), 

43 ("prompt.arg", "noinherit"), 

44 ("prompt.arg.text", ""), 

45 ("prompt.search", "noinherit"), 

46 ("prompt.search.text", ""), 

47 # Search toolbar. 

48 ("search-toolbar", "bold"), 

49 ("search-toolbar.text", "nobold"), 

50 # System toolbar 

51 ("system-toolbar", "bold"), 

52 ("system-toolbar.text", "nobold"), 

53 # "arg" toolbar. 

54 ("arg-toolbar", "bold"), 

55 ("arg-toolbar.text", "nobold"), 

56 # Validation toolbar. 

57 ("validation-toolbar", "bg:#550000 #ffffff"), 

58 ("window-too-small", "bg:#550000 #ffffff"), 

59 # Completions toolbar. 

60 ("completion-toolbar", "bg:#bbbbbb #000000"), 

61 ("completion-toolbar.arrow", "bg:#bbbbbb #000000 bold"), 

62 ("completion-toolbar.completion", "bg:#bbbbbb #000000"), 

63 ("completion-toolbar.completion.current", "bg:#444444 #ffffff"), 

64 # Completions menu. 

65 ("completion-menu", "bg:#bbbbbb #000000"), 

66 ("completion-menu.completion", ""), 

67 # (Note: for the current completion, we use 'reverse' on top of fg/bg 

68 # colors. This is to have proper rendering with NO_COLOR=1). 

69 ("completion-menu.completion.current", "fg:#888888 bg:#ffffff reverse"), 

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

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

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

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

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

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

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

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

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

79 # Styling of readline-like completions. 

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

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

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

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

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

85 # Scrollbars. 

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

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

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

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

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

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

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

93 # Auto suggestion text. 

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

95 # Trailing whitespace and tabs. 

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

97 ("tab", "#999999"), 

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

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

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

101 # Entering a Vi digraph. 

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

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

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

105 # Non-breaking space. 

106 ("nbsp", "underline ansiyellow"), 

107 # Default styling of HTML elements. 

108 ("i", "italic"), 

109 ("u", "underline"), 

110 ("s", "strike"), 

111 ("b", "bold"), 

112 ("em", "italic"), 

113 ("strong", "bold"), 

114 ("del", "strike"), 

115 ("hidden", "hidden"), 

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

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

118 ("italic", "italic"), 

119 ("underline", "underline"), 

120 ("strike", "strike"), 

121 ("bold", "bold"), 

122 ("reverse", "reverse"), 

123 ("noitalic", "noitalic"), 

124 ("nounderline", "nounderline"), 

125 ("nostrike", "nostrike"), 

126 ("nobold", "nobold"), 

127 ("noreverse", "noreverse"), 

128 # Prompt bottom toolbar 

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

130] 

131 

132 

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

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

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

136] 

137 

138 

139WIDGETS_STYLE = [ 

140 # Dialog windows. 

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

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

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

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

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

146 # Scrollbars in dialogs. 

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

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

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

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

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

152 # Buttons. 

153 ("button", ""), 

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

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

156 # Menu bars. 

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

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

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

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

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

162 # Shadows. 

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

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

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

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

167] 

168 

169 

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

171# is used. 

172PYGMENTS_DEFAULT_STYLE = { 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

214} 

215 

216 

217@memoized() 

218def default_ui_style() -> BaseStyle: 

219 """ 

220 Create a default `Style` object. 

221 """ 

222 return merge_styles( 

223 [ 

224 Style(PROMPT_TOOLKIT_STYLE), 

225 Style(COLORS_STYLE), 

226 Style(WIDGETS_STYLE), 

227 ] 

228 ) 

229 

230 

231@memoized() 

232def default_pygments_style() -> Style: 

233 """ 

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

235 """ 

236 return Style.from_dict(PYGMENTS_DEFAULT_STYLE)