mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 07:56:06 -03:30
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:
@@ -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)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
PyYAML>=5.1
|
PyYAML>=5.1
|
||||||
python-dateutil
|
python-dateutil
|
||||||
requests
|
requests
|
||||||
termcolor
|
|
||||||
|
|||||||
Reference in New Issue
Block a user