]>
Commit | Line | Data |
---|---|---|
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 = range(31, 37) | |
12 | ||
13 | class ColourMap(object): | |
14 | def __init__(self): | |
15 | self._cmap = {} | |
16 | self._colourIter = itertools.cycle(ANSI_COLOURS) | |
17 | ||
18 | def colourFor(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" |