mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
replace the termcolor dependency w/ a simple function
This commit is contained in:
parent
26637499d1
commit
224750c0d6
@ -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)
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
PyYAML>=5.1
|
||||
python-dateutil
|
||||
requests
|
||||
termcolor
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user