summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2015-12-18 18:52:00 +0100
committerMatthias Bussonnier <bussonniermatthias@gmail.com>2015-12-18 18:52:00 +0100
commit87b90dc3dacf1a5f668fe404fd2d62a23ecf9358 (patch)
treef1b87c0fce1ccf21d8d7a917161eae025086a9c0
parent2b910cf6b576321b1261379ca2be2d2f19d88ae1 (diff)
parent0121547da1fb4a8719bb2faec1b1501e5066eaf9 (diff)
downloadpygments-87b90dc3dacf1a5f668fe404fd2d62a23ecf9358.tar.gz
merge with origin
-rw-r--r--pygments/formatters/terminal256.py11
-rw-r--r--pygments/style.py7
2 files changed, 16 insertions, 2 deletions
diff --git a/pygments/formatters/terminal256.py b/pygments/formatters/terminal256.py
index af311955..9055b10b 100644
--- a/pygments/formatters/terminal256.py
+++ b/pygments/formatters/terminal256.py
@@ -27,6 +27,8 @@
import sys
from pygments.formatter import Formatter
+from pygments.console import codes
+from pygments.style import ansilist
__all__ = ['Terminal256Formatter', 'TerminalTrueColorFormatter']
@@ -47,7 +49,10 @@ class EscapeSequence:
def color_string(self):
attrs = []
if self.fg is not None:
- attrs.extend(("38", "5", "%i" % self.fg))
+ if self.fg in ansilist:
+ attrs.append(codes[self.fg[5:]][2:-1])
+ else :
+ attrs.extend(("38", "5", "%i" % self.fg))
if self.bg is not None:
attrs.extend(("48", "5", "%i" % self.bg))
if self.bold:
@@ -169,6 +174,10 @@ class Terminal256Formatter(Formatter):
def _color_index(self, color):
index = self.best_match.get(color, None)
+ if color in ansilist:
+ # strip the `#ansi` part an look up code
+ index = color
+ self.best_match[color] = index
if index is None:
try:
rgb = int(str(color), 16)
diff --git a/pygments/style.py b/pygments/style.py
index b2b990ea..637a9303 100644
--- a/pygments/style.py
+++ b/pygments/style.py
@@ -5,12 +5,15 @@
Basic style object.
- :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.token import Token, STANDARD_TYPES
from pygments.util import add_metaclass
+from pygments.console import codes
+
+ansilist = ['#ansi'+x for x in codes.keys()]
class StyleMeta(type):
@@ -22,6 +25,8 @@ class StyleMeta(type):
obj.styles[token] = ''
def colorformat(text):
+ if text in ansilist:
+ return text
if text[0:1] == '#':
col = text[1:]
if len(col) == 6: