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