| 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", |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
rich_style = { |
| 71 |
"markdown.code": friendly_style["code"], |
| 72 |
"repr.tag_name": friendly_style["code"], |
| 73 |
"markdown.h1": friendly_style["diagnostics"], |
| 74 |
|
| 75 |
"markdown.h2": friendly_style["Exception"], |
| 76 |
"markdown.h3": colours["mauve"], |
| 77 |
"markdown.h4": colours["orange"], |
| 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 |
|
| 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 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
friendly_style = friendly_style |
| 110 |
|
| 111 |
styles = { |
| 112 |
Text: friendly_style["text"], |
| 113 |
Whitespace: "", |
| 114 |
Error: "bg:#cc0000 #ffffff", |
| 115 |
Other: friendly_style["string"], |
| 116 |
|
| 117 |
Comment: friendly_style["comments"], |
| 118 |
Comment.Multiline: friendly_style["comments"], |
| 119 |
Comment.Preproc: friendly_style["comments"], |
| 120 |
Comment.Single: friendly_style["comments"], |
| 121 |
Comment.Special: friendly_style["comments"], |
| 122 |
|
| 123 |
Generic: friendly_style["text"], |
| 124 |
Generic.Deleted: friendly_style["Exception"], |
| 125 |
Generic.Emph: friendly_style["text"], |
| 126 |
Generic.Error: friendly_style["Exception"], |
| 127 |
Generic.Heading: friendly_style["text"], |
| 128 |
Generic.Inserted: friendly_style["text"], |
| 129 |
Generic.Output: friendly_style["text"], |
| 130 |
Generic.Prompt: friendly_style["keywords"], |
| 131 |
Generic.Strong: friendly_style["text"], |
| 132 |
Generic.Subheading: friendly_style["text"], |
| 133 |
Generic.Traceback: friendly_style["Exception"], |
| 134 |
|
| 135 |
Keyword: friendly_style["keywords"], |
| 136 |
Keyword.Constant: friendly_style["TrueFalseNone"], |
| 137 |
Keyword.Declaration: friendly_style["keywords"], |
| 138 |
Keyword.Namespace: friendly_style["keywords"], |
| 139 |
Keyword.Pseudo: friendly_style["keywords"], |
| 140 |
Keyword.Reserved: friendly_style["keywords"], |
| 141 |
Keyword.Type: friendly_style["keywords"], |
| 142 |
|
| 143 |
Literal: friendly_style["text"], |
| 144 |
Literal.Date: friendly_style["text"], |
| 145 |
|
| 146 |
Name: friendly_style["code"], |
| 147 |
Name.Attribute: friendly_style["code"], |
| 148 |
|
| 149 |
Name.Builtin: friendly_style["builtins"], |
| 150 |
Name.Builtin.Pseudo: friendly_style["builtins"], |
| 151 |
Name.Class: friendly_style["code"], |
| 152 |
Name.Constant: friendly_style["code"], |
| 153 |
Name.Decorator: friendly_style["code"], |
| 154 |
Name.Entity: friendly_style["code"], |
| 155 |
Name.Exception: friendly_style["Exception"], |
| 156 |
Name.Function: friendly_style["code"], |
| 157 |
Name.Property: friendly_style["code"], |
| 158 |
Name.Label: friendly_style["code"], |
| 159 |
Name.Namespace: friendly_style["code"], |
| 160 |
Name.Other: friendly_style["diagnostics"], |
| 161 |
Name.Tag: friendly_style["code"], |
| 162 |
Name.Variable: friendly_style["text"], |
| 163 |
Name.Variable.Class: friendly_style["code"], |
| 164 |
Name.Variable.Global: friendly_style["code"], |
| 165 |
Name.Variable.Instance: friendly_style["text"], |
| 166 |
|
| 167 |
Number: friendly_style["numbers"], |
| 168 |
Number.Float: friendly_style["numbers"], |
| 169 |
Number.Hex: friendly_style["numbers"], |
| 170 |
Number.Integer: friendly_style["numbers"], |
| 171 |
Number.Integer.Long: friendly_style["numbers"], |
| 172 |
Number.Oct: friendly_style["numbers"], |
| 173 |
|
| 174 |
Operator: friendly_style["operators"], |
| 175 |
Operator.Word: friendly_style["keywords"], |
| 176 |
|
| 177 |
Punctuation: friendly_style["operators"], |
| 178 |
|
| 179 |
String: friendly_style["string"], |
| 180 |
String.Backtick: friendly_style["string"], |
| 181 |
String.Char: friendly_style["string"], |
| 182 |
String.Doc: friendly_style["string"], |
| 183 |
String.Double: friendly_style["string"], |
| 184 |
String.Escape: friendly_style["string"], |
| 185 |
String.Heredoc: friendly_style["string"], |
| 186 |
String.Interpol: friendly_style["string"], |
| 187 |
String.Other: friendly_style["string"], |
| 188 |
String.Regex: friendly_style["string"], |
| 189 |
String.Single: friendly_style["string"], |
| 190 |
String.Symbol: friendly_style["string"], |
| 191 |
} |