summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorAnteru <bitbucket@ca.sh13.net>2018-12-16 16:37:33 +0000
committerAnteru <bitbucket@ca.sh13.net>2018-12-16 16:37:33 +0000
commit7b32e7ccb5ade830289b0c259df83eab191b0944 (patch)
tree8e1e2e23acf64bcf8d1f7827c56370f5c58f8e9c /pygments
parent59872dafd45ca9e25bd7b61afe31ca6d71aa5cd0 (diff)
parentd564ab9227416838ffb0363a716fa86f20025a4d (diff)
downloadpygments-7b32e7ccb5ade830289b0c259df83eab191b0944.tar.gz
Merged in mortenlund/pygments-main (pull request #777)
Change ansi color names to more saying names Approved-by: Morten E. Lund <melund@gmail.com> Approved-by: jonathanslenders <jonathan@slenders.be> Approved-by: Anteru <bitbucket@ca.sh13.net>
Diffstat (limited to 'pygments')
-rw-r--r--pygments/console.py11
-rw-r--r--pygments/formatters/terminal256.py12
-rw-r--r--pygments/style.py63
3 files changed, 57 insertions, 29 deletions
diff --git a/pygments/console.py b/pygments/console.py
index 31b6839d..e61744ce 100644
--- a/pygments/console.py
+++ b/pygments/console.py
@@ -22,10 +22,10 @@ codes["underline"] = esc + "04m"
codes["blink"] = esc + "05m"
codes["overline"] = esc + "06m"
-dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue",
- "purple", "teal", "lightgray"]
-light_colors = ["darkgray", "red", "green", "yellow", "blue",
- "fuchsia", "turquoise", "white"]
+dark_colors = ["black", "red", "green", "yellow", "blue",
+ "magenta", "cyan", "gray"]
+light_colors = ["brightblack", "brightred", "brightgreen", "brightyellow", "brightblue",
+ "brightmagenta", "brightcyan", "white"]
x = 30
for d, l in zip(dark_colors, light_colors):
@@ -35,9 +35,6 @@ for d, l in zip(dark_colors, light_colors):
del d, l, x
-codes["darkteal"] = codes["turquoise"]
-codes["darkyellow"] = codes["brown"]
-codes["fuscia"] = codes["fuchsia"]
codes["white"] = codes["bold"]
diff --git a/pygments/formatters/terminal256.py b/pygments/formatters/terminal256.py
index b80dc7dd..aec19804 100644
--- a/pygments/formatters/terminal256.py
+++ b/pygments/formatters/terminal256.py
@@ -50,7 +50,7 @@ class EscapeSequence:
attrs = []
if self.fg is not None:
if self.fg in ansicolors:
- esc = codes[self.fg[5:]]
+ esc = codes[self.fg.replace('ansi','')]
if ';01m' in esc:
self.bold = True
# extract fg color code.
@@ -59,7 +59,7 @@ class EscapeSequence:
attrs.extend(("38", "5", "%i" % self.fg))
if self.bg is not None:
if self.bg in ansicolors:
- esc = codes[self.bg[5:]]
+ esc = codes[self.bg.replace('ansi','')]
# extract fg color code, add 10 for bg.
attrs.append(str(int(esc[2:4])+10))
else:
@@ -110,6 +110,12 @@ class Terminal256Formatter(Formatter):
`Terminal256Formatter` will map these to non extended foreground color.
See :ref:`AnsiTerminalStyle` for more information.
+ .. versionchanged:: 2.3
+ The ansi color names have been updated with names that are easier to
+ understand and align with colornames of other projects and terminals.
+ See :ref:`NewAnsiColorNames` for more information.
+
+
Options accepted:
`style`
@@ -189,7 +195,7 @@ class Terminal256Formatter(Formatter):
def _color_index(self, color):
index = self.best_match.get(color, None)
if color in ansicolors:
- # strip the `#ansi` part and look up code
+ # strip the `ansi/#ansi` part and look up code
index = color
self.best_match[color] = index
if index is None:
diff --git a/pygments/style.py b/pygments/style.py
index 879c4e05..89766d8c 100644
--- a/pygments/style.py
+++ b/pygments/style.py
@@ -12,26 +12,47 @@
from pygments.token import Token, STANDARD_TYPES
from pygments.util import add_metaclass
-# Default mapping of #ansixxx to RGB colors.
+# Default mapping of ansixxx to RGB colors.
_ansimap = {
# dark
- '#ansiblack': '000000',
- '#ansidarkred': '7f0000',
- '#ansidarkgreen': '007f00',
- '#ansibrown': '7f7fe0',
- '#ansidarkblue': '00007f',
- '#ansipurple': '7f007f',
- '#ansiteal': '007f7f',
- '#ansilightgray': 'e5e5e5',
+ 'ansiblack': '000000',
+ 'ansired': '7f0000',
+ 'ansigreen': '007f00',
+ 'ansiyellow': '7f7fe0',
+ 'ansiblue': '00007f',
+ 'ansimagenta': '7f007f',
+ 'ansicyan': '007f7f',
+ 'ansigray': 'e5e5e5',
# normal
- '#ansidarkgray': '555555',
- '#ansired': 'ff0000',
- '#ansigreen': '00ff00',
- '#ansiyellow': 'ffff00',
- '#ansiblue': '0000ff',
- '#ansifuchsia': 'ff00ff',
- '#ansiturquoise': '00ffff',
- '#ansiwhite': 'ffffff',
+ 'ansibrightblack': '555555',
+ 'ansibrightred': 'ff0000',
+ 'ansibrightgreen': '00ff00',
+ 'ansibrightyellow': 'ffff00',
+ 'ansibrightblue': '0000ff',
+ 'ansibrightmagenta': 'ff00ff',
+ 'ansibrightcyan': '00ffff',
+ 'ansiwhite': 'ffffff',
+}
+# mapping of deprecated #ansixxx colors to new color names
+_deprecated_ansicolors = {
+ # dark
+ '#ansiblack': 'ansiblack',
+ '#ansidarkred': 'ansired',
+ '#ansidarkgreen': 'ansigreen',
+ '#ansibrown': 'ansiyellow',
+ '#ansidarkblue': 'ansiblue',
+ '#ansipurple': 'ansimagenta',
+ '#ansiteal': 'ansicyan',
+ '#ansilightgray': 'ansigray',
+ # normal
+ '#ansidarkgray': 'ansibrightblack',
+ '#ansired': 'ansibrightred',
+ '#ansigreen': 'ansibrightgreen',
+ '#ansiyellow': 'ansibrightyellow',
+ '#ansiblue': 'ansibrightblue',
+ '#ansifuchsia': 'ansibrightmagenta',
+ '#ansiturquoise': 'ansibrightcyan',
+ '#ansiwhite': 'ansiwhite',
}
ansicolors = set(_ansimap)
@@ -106,11 +127,15 @@ class StyleMeta(type):
t = cls._styles[token]
ansicolor = bgansicolor = None
color = t[0]
- if color.startswith('#ansi'):
+ if color in _deprecated_ansicolors:
+ color = _deprecated_ansicolors[color]
+ if color in ansicolors:
ansicolor = color
color = _ansimap[color]
bgcolor = t[4]
- if bgcolor.startswith('#ansi'):
+ if bgcolor in _deprecated_ansicolors:
+ bgcolor = _deprecated_ansicolors[color]
+ if bgcolor in ansicolors:
bgansicolor = bgcolor
bgcolor = _ansimap[bgcolor]