defaults.py 8.5 KB

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