Commit | Line | Data |
---|---|---|
6fa09c14 VNM |
1 | def basic_color(code): |
2 | """ | |
3 | 16 colors supported | |
4 | """ | |
be4dba0e | 5 | def inner(text, rl=False): |
9ee4a3cc O |
6 | """ |
7 | Every raw_input with color sequences should be called with | |
8 | rl=True to avoid readline messed up the length calculation | |
9 | """ | |
533edcdb | 10 | c = code |
be4dba0e | 11 | if rl: |
12 | return "\001\033[%sm\002%s\001\033[0m\002" % (c, text) | |
13 | else: | |
14 | return "\033[%sm%s\033[0m" % (c, text) | |
533edcdb | 15 | return inner |
8c840a83 | 16 | |
6fa09c14 | 17 | |
37ae740e | 18 | def term_color(code): |
6fa09c14 VNM |
19 | """ |
20 | 256 colors supported | |
21 | """ | |
be4dba0e | 22 | def inner(text, rl=False): |
9ee4a3cc O |
23 | """ |
24 | Every raw_input with color sequences should be called with | |
25 | rl=True to avoid readline messed up the length calculation | |
26 | """ | |
6fa09c14 | 27 | c = code |
be4dba0e | 28 | if rl: |
29 | return "\001\033[38;5;%sm\002%s\001\033[0m\002" % (c, text) | |
30 | else: | |
31 | return "\033[38;5;%sm%s\033[0m" % (c, text) | |
6fa09c14 VNM |
32 | return inner |
33 | ||
34 | ||
531f5682 O |
35 | """ |
36 | 16 basic colors | |
37 | """ | |
c075e6dc O |
38 | default = basic_color('39') |
39 | black = basic_color('30') | |
40 | red = basic_color('31') | |
41 | green = basic_color('32') | |
42 | yellow = basic_color('33') | |
43 | blue = basic_color('34') | |
44 | magenta = basic_color('35') | |
45 | cyan = basic_color('36') | |
46 | grey = basic_color('90') | |
47 | light_red = basic_color('91') | |
48 | light_green = basic_color('92') | |
49 | light_yellow = basic_color('93') | |
50 | light_blue = basic_color('94') | |
51 | light_magenta = basic_color('95') | |
52 | light_cyan = basic_color('96') | |
53 | white = basic_color('97') | |
6fa09c14 | 54 | |
531f5682 O |
55 | """ |
56 | 16 basic colors on background | |
57 | """ | |
c075e6dc O |
58 | on_default = basic_color('49') |
59 | on_black = basic_color('40') | |
60 | on_red = basic_color('41') | |
61 | on_green = basic_color('42') | |
62 | on_yellow = basic_color('43') | |
63 | on_blue = basic_color('44') | |
64 | on_magenta = basic_color('45') | |
65 | on_cyan = basic_color('46') | |
66 | on_grey = basic_color('100') | |
67 | on_light_red = basic_color('101') | |
68 | on_light_green = basic_color('102') | |
69 | on_light_yellow = basic_color('103') | |
70 | on_light_blue = basic_color('104') | |
6fa09c14 | 71 | on_light_magenta = basic_color('105') |
c075e6dc O |
72 | on_light_cyan = basic_color('106') |
73 | on_white = basic_color('107') |