eric6/ThirdParty/Pygments/pygments/style.py

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
equal deleted inserted replaced
7546:bf5f777260a6 7547:21b0534faebc
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):
50 if text[0:1] == '#': 70 if text[0:1] == '#':
51 col = text[1:] 71 col = text[1:]
52 if len(col) == 6: 72 if len(col) == 6:
53 return col 73 return col
54 elif len(col) == 3: 74 elif len(col) == 3:
55 return col[0]*2 + col[1]*2 + col[2]*2 75 return col[0] * 2 + col[1] * 2 + col[2] * 2
56 elif text == '': 76 elif text == '':
57 return '' 77 return ''
78 elif text.startswith('var') or text.startswith('calc'):
79 return text
58 assert False, "wrong color format %r" % text 80 assert False, "wrong color format %r" % text
59 81
60 _styles = obj._styles = {} 82 _styles = obj._styles = {}
61 83
62 for ttype in obj.styles: 84 for ttype in obj.styles:
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,
140 166
141 def __len__(cls): 167 def __len__(cls):
142 return len(cls._styles) 168 return len(cls._styles)
143 169
144 170
145 @add_metaclass(StyleMeta) 171 class Style(metaclass=StyleMeta):
146 class Style(object):
147 172
148 #: overall background color (``None`` means transparent) 173 #: overall background color (``None`` means transparent)
149 background_color = '#ffffff' 174 background_color = '#ffffff'
150 175
151 #: highlight background color 176 #: highlight background color

eric ide

mercurial