| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
from __future__ import unicode_literals |
| 18 |
|
| 19 |
import os |
| 20 |
import sys |
| 21 |
import platform |
| 22 |
|
| 23 |
SUPPORTS_ANSI = False |
| 24 |
for handle in [sys.stdout, sys.stderr]: |
| 25 |
if (hasattr(handle, "isatty") and handle.isatty()) or \ |
| 26 |
('TERM' in os.environ and os.environ['TERM'] == 'ANSI'): |
| 27 |
if platform.system() == 'Windows' and not ( |
| 28 |
'TERM' in os.environ and os.environ['TERM'] == 'ANSI'): |
| 29 |
SUPPORTS_ANSI = False |
| 30 |
else: |
| 31 |
SUPPORTS_ANSI = True |
| 32 |
|
| 33 |
if os.getenv('SURE_NO_COLORS'): |
| 34 |
SUPPORTS_ANSI = False |
| 35 |
|
| 36 |
SUPPORTS_ANSI = False |
| 37 |
|
| 38 |
|
| 39 |
def red(string): |
| 40 |
if not SUPPORTS_ANSI: |
| 41 |
return string |
| 42 |
return r"\033[1;31m{0}\033[0m".format(string) |
| 43 |
|
| 44 |
|
| 45 |
def green(string): |
| 46 |
if not SUPPORTS_ANSI: |
| 47 |
return string |
| 48 |
return r"\033[1;32m{0}\033[0m".format(string) |
| 49 |
|
| 50 |
|
| 51 |
def yellow(string): |
| 52 |
if not SUPPORTS_ANSI: |
| 53 |
return string |
| 54 |
return r"\033[1;33m{0}\033[0m".format(string) |
| 55 |
|
| 56 |
|
| 57 |
def white(string): |
| 58 |
if not SUPPORTS_ANSI: |
| 59 |
return string |
| 60 |
return r"\033[1;37m{0}\033[0m".format(string) |