3 pygments.style |
3 pygments.style |
4 ~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~ |
5 |
5 |
6 Basic style object. |
6 Basic style object. |
7 |
7 |
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from pygments.token import Token, STANDARD_TYPES |
12 from pygments.token import Token, STANDARD_TYPES |
13 from pygments.util import add_metaclass |
|
14 |
13 |
15 # Default mapping of #ansixxx to RGB colors. |
14 # Default mapping of ansixxx to RGB colors. |
16 _ansimap = { |
15 _ansimap = { |
17 # dark |
16 # dark |
18 '#ansiblack': '000000', |
17 'ansiblack': '000000', |
19 '#ansidarkred': '7f0000', |
18 'ansired': '7f0000', |
20 '#ansidarkgreen': '007f00', |
19 'ansigreen': '007f00', |
21 '#ansibrown': '7f7fe0', |
20 'ansiyellow': '7f7fe0', |
22 '#ansidarkblue': '00007f', |
21 'ansiblue': '00007f', |
23 '#ansipurple': '7f007f', |
22 'ansimagenta': '7f007f', |
24 '#ansiteal': '007f7f', |
23 'ansicyan': '007f7f', |
25 '#ansilightgray': 'e5e5e5', |
24 'ansigray': 'e5e5e5', |
26 # normal |
25 # normal |
27 '#ansidarkgray': '555555', |
26 'ansibrightblack': '555555', |
28 '#ansired': 'ff0000', |
27 'ansibrightred': 'ff0000', |
29 '#ansigreen': '00ff00', |
28 'ansibrightgreen': '00ff00', |
30 '#ansiyellow': 'ffff00', |
29 'ansibrightyellow': 'ffff00', |
31 '#ansiblue': '0000ff', |
30 'ansibrightblue': '0000ff', |
32 '#ansifuchsia': 'ff00ff', |
31 'ansibrightmagenta': 'ff00ff', |
33 '#ansiturquoise': '00ffff', |
32 'ansibrightcyan': '00ffff', |
34 '#ansiwhite': 'ffffff', |
33 'ansiwhite': 'ffffff', |
|
34 } |
|
35 # mapping of deprecated #ansixxx colors to new color names |
|
36 _deprecated_ansicolors = { |
|
37 # dark |
|
38 '#ansiblack': 'ansiblack', |
|
39 '#ansidarkred': 'ansired', |
|
40 '#ansidarkgreen': 'ansigreen', |
|
41 '#ansibrown': 'ansiyellow', |
|
42 '#ansidarkblue': 'ansiblue', |
|
43 '#ansipurple': 'ansimagenta', |
|
44 '#ansiteal': 'ansicyan', |
|
45 '#ansilightgray': 'ansigray', |
|
46 # normal |
|
47 '#ansidarkgray': 'ansibrightblack', |
|
48 '#ansired': 'ansibrightred', |
|
49 '#ansigreen': 'ansibrightgreen', |
|
50 '#ansiyellow': 'ansibrightyellow', |
|
51 '#ansiblue': 'ansibrightblue', |
|
52 '#ansifuchsia': 'ansibrightmagenta', |
|
53 '#ansiturquoise': 'ansibrightcyan', |
|
54 '#ansiwhite': 'ansiwhite', |
35 } |
55 } |
36 ansicolors = set(_ansimap) |
56 ansicolors = set(_ansimap) |
37 |
57 |
38 |
58 |
39 class StyleMeta(type): |
59 class StyleMeta(type): |
104 |
126 |
105 def style_for_token(cls, token): |
127 def style_for_token(cls, token): |
106 t = cls._styles[token] |
128 t = cls._styles[token] |
107 ansicolor = bgansicolor = None |
129 ansicolor = bgansicolor = None |
108 color = t[0] |
130 color = t[0] |
109 if color.startswith('#ansi'): |
131 if color in _deprecated_ansicolors: |
|
132 color = _deprecated_ansicolors[color] |
|
133 if color in ansicolors: |
110 ansicolor = color |
134 ansicolor = color |
111 color = _ansimap[color] |
135 color = _ansimap[color] |
112 bgcolor = t[4] |
136 bgcolor = t[4] |
113 if bgcolor.startswith('#ansi'): |
137 if bgcolor in _deprecated_ansicolors: |
|
138 bgcolor = _deprecated_ansicolors[color] |
|
139 if bgcolor in ansicolors: |
114 bgansicolor = bgcolor |
140 bgansicolor = bgcolor |
115 bgcolor = _ansimap[bgcolor] |
141 bgcolor = _ansimap[bgcolor] |
116 |
142 |
117 return { |
143 return { |
118 'color': color or None, |
144 'color': color or None, |