replace the termcolor dependency w/ a simple function

This commit is contained in:
Ryan Petrello 2019-08-15 09:41:44 -04:00
parent 26637499d1
commit 224750c0d6
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 26 additions and 12 deletions

View File

@ -1,8 +1,7 @@
from argparse import ArgumentParser
import threading
import os
import sys
import termcolor
import threading
_color = threading.local()
_color.enabled = True
@ -62,15 +61,31 @@ def disable_color():
_color.enabled = False
def colored(value, color):
if _color.enabled:
return termcolor.colored(value, color)
else:
return value
COLORS = dict(
list(
zip(
[
'grey', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan',
'white',
],
list(range(30, 38))
)
)
)
def cprint(value, color, **kwargs):
def colored(text, color=None):
'''Colorize text w/ ANSI color sequences'''
if _color.enabled and os.getenv('ANSI_COLORS_DISABLED') is None:
fmt_str = '\033[%dm%s'
if color is not None:
text = fmt_str % (COLORS[color], text)
text += '\033[0m'
return text
def cprint(text, color, **kwargs):
if _color.enabled:
termcolor.cprint(value, color, **kwargs)
print(colored(text, color), **kwargs)
else:
print(value, **kwargs)
print(text, **kwargs)

View File

@ -1,4 +1,3 @@
PyYAML>=5.1
python-dateutil
requests
termcolor