]> jfr.im git - z_archive/twitter.git/blame - twitter/ansi.py
Support for colours in command-line tool.
[z_archive/twitter.git] / twitter / ansi.py
CommitLineData
7522aa11
MV
1"""
2Support for ANSI colours in command-line client.
3
4"""
5
6import itertools
7
8ESC = chr(0x1B)
9RESET = "0"
10
0b9960a3 11COLOURS = [str(x) for x in range(31, 37)]
7522aa11
MV
12
13class ColourMap(object):
14 def __init__(self):
15 self._cmap = {}
0b9960a3 16 self._colourIter = itertools.cycle(COLOURS)
7522aa11 17
0b9960a3 18 def colourFor(self, string):
7522aa11
MV
19 if not self._cmap.has_key(string):
20 self._cmap[string] = self._colourIter.next()
21 return self._cmap[string]
22
23def cmdReset():
24 return ESC + "[0m"
25
26def cmdColour(colour):
27 return ESC + "[" + colour + "m"