Merge pull request #4491 from ryanpetrello/remove-cli-termcolor

replace the termcolor dependency w/ a simple function

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-08-15 14:25:39 +00:00
committed by GitHub
2 changed files with 26 additions and 12 deletions

View File

@@ -1,8 +1,7 @@
from argparse import ArgumentParser from argparse import ArgumentParser
import threading import os
import sys import sys
import threading
import termcolor
_color = threading.local() _color = threading.local()
_color.enabled = True _color.enabled = True
@@ -62,15 +61,31 @@ def disable_color():
_color.enabled = False _color.enabled = False
def colored(value, color): COLORS = dict(
if _color.enabled: list(
return termcolor.colored(value, color) zip(
else: [
return value '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: if _color.enabled:
termcolor.cprint(value, color, **kwargs) print(colored(text, color), **kwargs)
else: else:
print(value, **kwargs) print(text, **kwargs)

View File

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