| 1 | def basic_color(code): |
| 2 | """ |
| 3 | 16 colors supported |
| 4 | """ |
| 5 | def inner(text, rl=False): |
| 6 | """ |
| 7 | Every raw_input with color sequences should be called with |
| 8 | rl=True to avoid readline messed up the length calculation |
| 9 | """ |
| 10 | c = code |
| 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) |
| 15 | return inner |
| 16 | |
| 17 | |
| 18 | def term_color(code): |
| 19 | """ |
| 20 | 256 colors supported |
| 21 | """ |
| 22 | def inner(text, rl=False): |
| 23 | """ |
| 24 | Every raw_input with color sequences should be called with |
| 25 | rl=True to avoid readline messed up the length calculation |
| 26 | """ |
| 27 | c = code |
| 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) |
| 32 | return inner |
| 33 | |
| 34 | |
| 35 | """ |
| 36 | 16 basic colors |
| 37 | """ |
| 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') |
| 54 | |
| 55 | """ |
| 56 | 16 basic colors on background |
| 57 | """ |
| 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') |
| 71 | on_light_magenta = basic_color('105') |
| 72 | on_light_cyan = basic_color('106') |
| 73 | on_white = basic_color('107') |