summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2015-11-04 20:29:24 -0800
committerMatthias Bussonnier <bussonniermatthias@gmail.com>2015-11-04 20:29:24 -0800
commit0121547da1fb4a8719bb2faec1b1501e5066eaf9 (patch)
treecdf1f01ee868031f7c54fe14ed14e6159862652f /pygments
parent39b04c956deca69ff5befcfdcc76c5212f65d972 (diff)
downloadpygments-0121547da1fb4a8719bb2faec1b1501e5066eaf9.tar.gz
Allow ansi escape sequence as color format
Diffstat (limited to 'pygments')
-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: