2013-09-22 20:39:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
pygments.console
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Format colored console output.
|
|
|
|
|
2017-02-14 07:25:51 +00:00
|
|
|
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
2013-09-22 20:39:16 +00:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
esc = "\x1b["
|
|
|
|
|
|
|
|
codes = {}
|
2017-02-14 07:25:51 +00:00
|
|
|
codes[""] = ""
|
|
|
|
codes["reset"] = esc + "39;49;00m"
|
2013-09-22 20:39:16 +00:00
|
|
|
|
2017-02-14 07:25:51 +00:00
|
|
|
codes["bold"] = esc + "01m"
|
|
|
|
codes["faint"] = esc + "02m"
|
|
|
|
codes["standout"] = esc + "03m"
|
2013-09-22 20:39:16 +00:00
|
|
|
codes["underline"] = esc + "04m"
|
2017-02-14 07:25:51 +00:00
|
|
|
codes["blink"] = esc + "05m"
|
|
|
|
codes["overline"] = esc + "06m"
|
2013-09-22 20:39:16 +00:00
|
|
|
|
2017-02-14 07:25:51 +00:00
|
|
|
dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue",
|
|
|
|
"purple", "teal", "lightgray"]
|
2013-09-22 20:39:16 +00:00
|
|
|
light_colors = ["darkgray", "red", "green", "yellow", "blue",
|
|
|
|
"fuchsia", "turquoise", "white"]
|
|
|
|
|
|
|
|
x = 30
|
|
|
|
for d, l in zip(dark_colors, light_colors):
|
|
|
|
codes[d] = esc + "%im" % x
|
|
|
|
codes[l] = esc + "%i;01m" % x
|
|
|
|
x += 1
|
|
|
|
|
|
|
|
del d, l, x
|
|
|
|
|
2017-02-14 07:25:51 +00:00
|
|
|
codes["darkteal"] = codes["turquoise"]
|
2013-09-22 20:39:16 +00:00
|
|
|
codes["darkyellow"] = codes["brown"]
|
2017-02-14 07:25:51 +00:00
|
|
|
codes["fuscia"] = codes["fuchsia"]
|
|
|
|
codes["white"] = codes["bold"]
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reset_color():
|
|
|
|
return codes["reset"]
|
|
|
|
|
|
|
|
|
|
|
|
def colorize(color_key, text):
|
|
|
|
return codes[color_key] + text + codes["reset"]
|
|
|
|
|
|
|
|
|
|
|
|
def ansiformat(attr, text):
|
|
|
|
"""
|
|
|
|
Format ``text`` with a color and/or some attributes::
|
|
|
|
|
|
|
|
color normal color
|
|
|
|
*color* bold color
|
|
|
|
_color_ underlined color
|
|
|
|
+color+ blinking color
|
|
|
|
"""
|
|
|
|
result = []
|
|
|
|
if attr[:1] == attr[-1:] == '+':
|
|
|
|
result.append(codes['blink'])
|
|
|
|
attr = attr[1:-1]
|
|
|
|
if attr[:1] == attr[-1:] == '*':
|
|
|
|
result.append(codes['bold'])
|
|
|
|
attr = attr[1:-1]
|
|
|
|
if attr[:1] == attr[-1:] == '_':
|
|
|
|
result.append(codes['underline'])
|
|
|
|
attr = attr[1:-1]
|
|
|
|
result.append(codes[attr])
|
|
|
|
result.append(text)
|
|
|
|
result.append(codes['reset'])
|
|
|
|
return ''.join(result)
|