Debian Codegraph @

friendly_styles/friendly_light.py

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