]>
Commit | Line | Data |
---|---|---|
7522aa11 MV |
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 | ||
0b9960a3 | 11 | COLOURS = [str(x) for x in range(31, 37)] |
7522aa11 MV |
12 | |
13 | class 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 | ||
23 | def cmdReset(): | |
24 | return ESC + "[0m" | |
25 | ||
26 | def cmdColour(colour): | |
27 | return ESC + "[" + colour + "m" |