summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>2010-04-29 18:35:07 +0200
committerNicolas Chauvat <nicolas.chauvat@logilab.fr>2010-04-29 18:35:07 +0200
commit8b8a9966e49dd29c621d7a33a7f249250b2ffbc5 (patch)
tree071e437b038e7c1a94b487382cf34b49bcd19eaa
parentd4f2cc807a3acb9a5ca5e70d123bd834c8134484 (diff)
downloadlogilab-common-8b8a9966e49dd29c621d7a33a7f249250b2ffbc5.tar.gz
[textutils] support 256 colors when available
-rw-r--r--textutils.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/textutils.py b/textutils.py
index e5ef28e..275bddb 100644
--- a/textutils.py
+++ b/textutils.py
@@ -395,13 +395,13 @@ ANSI_COLORS = {
'white' : "37",
}
-
def _get_ansi_code(color=None, style=None):
"""return ansi escape code corresponding to color and style
:type color: str or None
:param color:
- the color identifier (see `ANSI_COLORS` for available values)
+ the color name (see `ANSI_COLORS` for available values)
+ or the color number when 256 colors are available
:type style: str or None
:param style:
@@ -418,7 +418,10 @@ def _get_ansi_code(color=None, style=None):
style_attrs = splitstrip(style)
for effect in style_attrs:
ansi_code.append(ANSI_STYLES[effect])
- if color:
+ if color.isdigit():
+ ansi_code.extend(['38','5'])
+ ansi_code.append(color)
+ else:
ansi_code.append(ANSI_COLORS[color])
if ansi_code:
return ANSI_PREFIX + ';'.join(ansi_code) + ANSI_END