Debian Codegraph @

friendly_styles/friendly_dark.py

raw symbols SCIP
1 """Theme designed for friendly [friendly-traceback]
2
3 This theme has colours chosen for a dark (black) background.
4
5 friendly uses Pygments themes mostly through
6 Rich [https://github.com/willmcgugan/rich].
7
8 Rich's console has styles for some objects that are defined
9 independently from a chosen Pygments theme.
10 In this file, we define a consistent theme which results
11 in the same colour shown for a certain object type whether
12 the colouring is done by Pygments or directly by Rich.
13 """
14
15 from pygments.style import Style
16 from pygments.token import (
17 Keyword,
18 Name,
19 Comment,
20 String,
21 Error,
22 Text,
23 Number,
24 Operator,
25 Generic,
26 Whitespace,
27 Punctuation,
28 Other,
29 Literal,
30 )
31
32
33 colours = {
34 "yellow": "#F0E68C",
35 "orange": "#FF8243",
36 "red": "#D92121",
37 "white": "#F4F0EC",
38 "beige": "#DEB887",
39 "blue": "#87CEEB",
40 "gray": "#666666",
41 "green": "#87A96B",
42 "mauve": "#9370DB",
43 "black": "#101010",
44 }
45
46 friendly_style = {
47 "builtins": colours["yellow"],
48 "code": colours["beige"],
49 "comments": colours["gray"],
50 "keywords": colours["yellow"],
51 "numbers": colours["white"],
52 "operators": colours["blue"],
53 "string": colours["green"],
54 "text": colours["white"],
55 "TrueFalseNone": colours["orange"],
56 "Exception": colours["red"],
57 "diagnostics": "#FF00FF", # Magenta; when trying to figure out a category
58 }
59
60 # Since we use Rich's pretty(), we try to ensure that the colours
61 # are consistent. pretty() highlight objects based on their repr name,
62 # while code highlighting is done by pygments based on different
63 # definitions.
64 # Rich defines some default values in
65 # https://github.com/willmcgugan/rich/blob/master/rich/default_styles.py
66 #
67
68 rich_style = {
69 "markdown.code": friendly_style["code"],
70 "repr.tag_name": friendly_style["code"], # for consistency with Python
71 "markdown.h1": friendly_style["diagnostics"],
72 # Exception message; location header H2
73 "markdown.h2": friendly_style["Exception"],
74 "markdown.h3": colours["mauve"], # likely cause
75 "markdown.h4": colours["orange"], # warning header
76 "markdown.link": f"underline {friendly_style['keywords']}",
77 "markdown.item.bullet": friendly_style["code"],
78 "repr.url": friendly_style["keywords"],
79 "repr.number": friendly_style["numbers"],
80 # The next three are identical for pygments, so we keep them identical
81 "repr.bool_false": friendly_style["TrueFalseNone"],
82 "repr.bool_true": friendly_style["TrueFalseNone"],
83 "repr.none": friendly_style["TrueFalseNone"],
84 #
85 "repr.str": friendly_style["string"],
86 "repr.error": friendly_style["Exception"],
87 "repr.indent": friendly_style["comments"],
88 "repr.attrib_name": friendly_style["builtins"],
89 "repr.attrib_value": friendly_style["code"],
90 "repr.attrib_equal": friendly_style["operators"],
91 "repr.call": friendly_style["code"],
92 }
93
94 friendly_style.update(**rich_style)
95
96
97 class FriendlyDarkStyle(Style):
98 """Theme designed for friendly/friendly-traceback
99 suitable for a black or very dark background.
100 """
101 background_color = colours["black"]
102 default_style = "#363636"
103 # Pygments styles are registered in such a way that only this class
104 # is accessible, normally preventing the above definitions
105 # (needed for specifying a theme for Rich) from being accessible.
106 # This class variable makes them available.
107 friendly_style = friendly_style
108
109 styles = {
110 Text: friendly_style["text"], # class: ''
111 Whitespace: "", # class: 'w'
112 Error: "bg:#ff0000 #ffffff", # class: 'err'
113 Other: friendly_style["string"], # class 'x'
114 #
115 Comment: friendly_style["comments"], # class: 'c'
116 Comment.Multiline: friendly_style["comments"], # class: 'cm'
117 Comment.Preproc: friendly_style["comments"], # class: 'cp'
118 Comment.Single: friendly_style["comments"], # class: 'c1'
119 Comment.Special: friendly_style["comments"], # class: 'cs'
120 #
121 Generic: friendly_style["text"], # class: 'g'
122 Generic.Deleted: friendly_style["Exception"], # class: 'gd'
123 Generic.Emph: friendly_style["text"], # class: 'ge'
124 Generic.Error: friendly_style["Exception"], # class: 'gr'
125 Generic.Heading: friendly_style["text"], # class: 'gh'
126 Generic.Inserted: friendly_style["text"], # class: 'gi'
127 Generic.Output: friendly_style["text"], # class: 'go'
128 Generic.Prompt: friendly_style["keywords"], # class: 'gp'
129 Generic.Strong: friendly_style["text"], # class: 'gs'
130 Generic.Subheading: friendly_style["text"], # class: 'gu'
131 Generic.Traceback: friendly_style["Exception"], # class: 'gt'
132 #
133 Keyword: friendly_style["keywords"], # class: 'k'
134 Keyword.Constant: friendly_style["TrueFalseNone"], # class: 'kc'
135 Keyword.Declaration: friendly_style["keywords"], # class: 'kd'
136 Keyword.Namespace: friendly_style["keywords"], # class: 'kn'
137 Keyword.Pseudo: friendly_style["keywords"], # class: 'kp'
138 Keyword.Reserved: friendly_style["keywords"], # class: 'kr'
139 Keyword.Type: friendly_style["keywords"], # class: 'kt'
140 #
141 Literal: friendly_style["text"], # class: 'l'
142 Literal.Date: friendly_style["text"], # class: 'ld'
143 #
144 Name: friendly_style["code"], # class: 'n'
145 Name.Attribute: friendly_style["code"], # class: 'na'
146 # The following is for file path in tracebacks and Python builtins.
147 Name.Builtin: friendly_style["builtins"], # class: 'nb'
148 Name.Builtin.Pseudo: friendly_style["builtins"], # class: 'bp'
149 Name.Class: friendly_style["code"], # class: 'nc'
150 Name.Constant: friendly_style["code"], # class: 'no'
151 Name.Decorator: friendly_style["code"], # class: 'nd'
152 Name.Entity: friendly_style["code"], # class: 'ni'
153 Name.Exception: friendly_style["Exception"], # class: 'ne'
154 Name.Function: friendly_style["code"], # class: 'nf'
155 Name.Property: friendly_style["code"], # class: 'py'
156 Name.Label: friendly_style["code"], # class: 'nl'
157 Name.Namespace: friendly_style["code"], # class: 'nn'
158 Name.Other: friendly_style["diagnostics"], # class: 'nx'
159 Name.Tag: friendly_style["code"], # class: 'nt' - like a keyword
160 Name.Variable: friendly_style["text"], # class: 'nv'
161 Name.Variable.Class: friendly_style["code"], # class: 'vc'
162 Name.Variable.Global: friendly_style["code"], # class: 'vg'
163 Name.Variable.Instance: friendly_style["text"], # class: 'vi'
164 #
165 Number: friendly_style["numbers"], # class: 'm'
166 Number.Float: friendly_style["numbers"], # class: 'mf'
167 Number.Hex: friendly_style["numbers"], # class: 'mh'
168 Number.Integer: friendly_style["numbers"], # class: 'mi'
169 Number.Integer.Long: friendly_style["numbers"], # class: 'il'
170 Number.Oct: friendly_style["numbers"], # class: 'mo'
171 #
172 Operator: friendly_style["operators"], # class: 'o'
173 Operator.Word: friendly_style["keywords"], # class: 'ow'
174 #
175 Punctuation: friendly_style["operators"], # class: 'p'
176 #
177 String: friendly_style["string"], # class: 's'
178 String.Backtick: friendly_style["string"], # class: 'sb'
179 String.Char: friendly_style["string"], # class: 'sc'
180 String.Doc: friendly_style["string"], # class: 'sd'
181 String.Double: friendly_style["string"], # class: 's2'
182 String.Escape: friendly_style["string"], # class: 'se'
183 String.Heredoc: friendly_style["string"], # class: 'sh'
184 String.Interpol: friendly_style["string"], # class: 'si'
185 String.Other: friendly_style["string"], # class: 'sx'
186 String.Regex: friendly_style["string"], # class: 'sr'
187 String.Single: friendly_style["string"], # class: 's1'
188 String.Symbol: friendly_style["string"], # class: 'ss'
189 }