66
64
COMMENT = make_style(fg='blue', opts=('bold',))
68
66
return lambda text: colorize(text, opts, **kwargs)
68
NOCOLOR_PALETTE = 'nocolor'
70
LIGHT_PALETTE = 'light'
83
'HTTP_NOT_MODIFIED': {},
84
'HTTP_BAD_REQUEST': {},
86
'HTTP_SERVER_ERROR': {},
89
'ERROR': { 'fg': 'red', 'opts': ('bold',) },
90
'NOTICE': { 'fg': 'red' },
91
'SQL_FIELD': { 'fg': 'green', 'opts': ('bold',) },
92
'SQL_COLTYPE': { 'fg': 'green' },
93
'SQL_KEYWORD': { 'fg': 'yellow' },
94
'SQL_TABLE': { 'opts': ('bold',) },
95
'HTTP_INFO': { 'opts': ('bold',) },
97
'HTTP_REDIRECT': { 'fg': 'green' },
98
'HTTP_NOT_MODIFIED': { 'fg': 'cyan' },
99
'HTTP_BAD_REQUEST': { 'fg': 'red', 'opts': ('bold',) },
100
'HTTP_NOT_FOUND': { 'fg': 'yellow' },
101
'HTTP_SERVER_ERROR': { 'fg': 'magenta', 'opts': ('bold',) },
104
'ERROR': { 'fg': 'red', 'opts': ('bold',) },
105
'NOTICE': { 'fg': 'red' },
106
'SQL_FIELD': { 'fg': 'green', 'opts': ('bold',) },
107
'SQL_COLTYPE': { 'fg': 'green' },
108
'SQL_KEYWORD': { 'fg': 'blue' },
109
'SQL_TABLE': { 'opts': ('bold',) },
110
'HTTP_INFO': { 'opts': ('bold',) },
112
'HTTP_REDIRECT': { 'fg': 'green', 'opts': ('bold',) },
113
'HTTP_NOT_MODIFIED': { 'fg': 'green' },
114
'HTTP_BAD_REQUEST': { 'fg': 'red', 'opts': ('bold',) },
115
'HTTP_NOT_FOUND': { 'fg': 'red' },
116
'HTTP_SERVER_ERROR': { 'fg': 'magenta', 'opts': ('bold',) },
119
DEFAULT_PALETTE = DARK_PALETTE
121
def parse_color_setting(config_string):
122
"""Parse a DJANGO_COLORS environment variable to produce the system palette
124
The general form of a pallete definition is:
126
"palette;role=fg;role=fg/bg;role=fg,option,option;role=fg/bg,option,option"
129
palette is a named palette; one of 'light', 'dark', or 'nocolor'.
130
role is a named style used by Django
131
fg is a background color.
132
bg is a background color.
133
option is a display options.
135
Specifying a named palette is the same as manually specifying the individual
136
definitions for each role. Any individual definitions following the pallete
137
definition will augment the base palette definition.
140
'error', 'notice', 'sql_field', 'sql_coltype', 'sql_keyword', 'sql_table',
141
'http_info', 'http_success', 'http_redirect', 'http_bad_request',
142
'http_not_found', 'http_server_error'
145
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
148
'bold', 'underscore', 'blink', 'reverse', 'conceal'
151
if not config_string:
152
return PALETTES[DEFAULT_PALETTE]
154
# Split the color configuration into parts
155
parts = config_string.lower().split(';')
156
palette = PALETTES[NOCOLOR_PALETTE].copy()
159
# A default palette has been specified
160
palette.update(PALETTES[part])
162
# Process a palette defining string
165
# Break the definition into the role,
166
# plus the list of specific instructions.
167
# The role must be in upper case
168
role, instructions = part.split('=')
171
styles = instructions.split(',')
174
# The first instruction can contain a slash
175
# to break apart fg/bg.
176
colors = styles.pop().split('/')
179
if fg in color_names:
180
definition['fg'] = fg
181
if colors and colors[-1] in color_names:
182
definition['bg'] = colors[-1]
184
# All remaining instructions are options
185
opts = tuple(s for s in styles if s in opt_dict.keys())
187
definition['opts'] = opts
189
# The nocolor palette has all available roles.
190
# Use that palette as the basis for determining
191
# if the role is valid.
192
if role in PALETTES[NOCOLOR_PALETTE] and definition:
193
palette[role] = definition
195
# If there are no colors specified, return the empty palette.
196
if palette == PALETTES[NOCOLOR_PALETTE]: