correctly detect a numeric color argument

This commit is contained in:
Alex Burka 2013-04-06 20:58:15 -04:00
commit c8a24b0aa8

View file

@ -197,7 +197,7 @@ def colorin(text, color="red", style="normal"):
color_code = str(30 + colors[color]) color_code = str(30 + colors[color])
# 256 colors mode # 256 colors mode
elif isinstance( color, int ): elif color.isdigit():
mode = 256 mode = 256
color_nb = int(color) color_nb = int(color)
assert(0 <= color_nb <= 255) assert(0 <= color_nb <= 255)
@ -221,6 +221,10 @@ def colorin(text, color="red", style="normal"):
# because Pygments adds a newline char. # because Pygments adds a newline char.
return highlight(text, lexer, formatter)[:-1] return highlight(text, lexer, formatter)[:-1]
# unrecognized
else:
raise Exception('Unrecognized color %s' % color)
return start + style_code + endmarks[mode] + color_code + "m" + text + stop return start + style_code + endmarks[mode] + color_code + "m" + text + stop