Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'colorama' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
def print_banner(color=True):
"""Prints an Alarmageddon banner in color if the caller requests it
and stdout is a terminal. PEP8 is temporarily suspended...
"""
if color and sys.stdout.isatty():
# Print a color version of the banner
init()
print("")
print((Fore.WHITE + " " + Style.DIM + "( " + Style.NORMAL + "." + Style.DIM + " ( ) :" + Style.NORMAL + "." + Style.DIM + " ) " +
Style.NORMAL + Fore.YELLOW + ". , // . , " + Fore.GREEN + "/\\"))
print((Fore.WHITE + " " + Style.DIM + "( ( ) ) " + Style.NORMAL + Fore.YELLOW + ". // . " + Fore.GREEN + "/\\/ \\/\\"))
print((Fore.WHITE + " " + Style.DIM + "( : " + Style.NORMAL + "*" + Style.DIM + " ( ) " + Style.NORMAL + " * " + Fore.YELLOW +
". // . " + Fore.GREEN + "( " + Fore.RED + ">" + Fore.GREEN + "\\ /" + Fore.RED + "<" + Fore.GREEN + " )"))
print((Fore.WHITE + " * " + Style.DIM + " ( : ) " + Style.NORMAL + Fore.YELLOW + ". // . . " + Fore.GREEN + "/ `__` \\"))
print((Fore.WHITE + " " + Style.DIM + "( : : ) " + Style.NORMAL + " * " + Fore.RED + Style.BRIGHT + " O" + Fore.YELLOW + Style.NORMAL +
" . " + Fore.GREEN + "\\ /" + Fore.WHITE + "VVVV" + Fore.GREEN + "\ /"))
print((Fore.WHITE + " * " + Style.DIM + " ( : ) " + Style.NORMAL + Fore.RED + "/" + Fore.WHITE + "IIIIIII" + Fore.RED +
"/[]\\ "))
print((Fore.WHITE + " . " + Fore.RED + "||||" + Fore.WHITE + " . " + Fore.WHITE + Style.DIM + "d" + Style.NORMAL + Fore.RED + "_" + Fore.WHITE + "O" + Fore.RED +
"______" + Fore.WHITE + "O" + Fore.RED + "___" + Style.DIM + Fore.WHITE + "b" + Style.NORMAL))
print((Fore.WHITE + " . " + Fore.RED + "||||" + Fore.WHITE + " . \\o/ \\o/ " + Fore.GREEN + " __ \\" + Fore.WHITE + "^^^^" +
Fore.GREEN + "/ \ "))
print((Fore.WHITE + " " + Fore.MAGENTA + "_/ " + Fore.YELLOW + "@ @@" + Fore.MAGENTA + "_" + Fore.WHITE + " | | " +
Fore.GREEN + "/ /\\ \__/ \ "))
print((Fore.WHITE + " " + Fore.MAGENTA + "/ " + Fore.YELLOW + "@ @" + Fore.MAGENTA + " \ " + Fore.WHITE + " // \\\\ " +
JAR_C_PATTERN3 = os.path.join(BASEDIR, "../../sonar-c-plugin/target/*RC[0-9].jar")
RELPATH_PLUGINS = "extensions/plugins"
didstartsonar = False
RED = ""
YELLOW = ""
GREEN = ""
RESET = ""
RESET_ALL = ""
BRIGHT = ""
try:
import colorama
colorama.init()
RED = colorama.Fore.RED
YELLOW = colorama.Fore.YELLOW
GREEN = colorama.Fore.GREEN
RESET = colorama.Fore.RESET
BRIGHT = colorama.Style.BRIGHT
RESET_ALL = colorama.Style.RESET_ALL
except ImportError:
pass
# -----------------------------------------------------------------------------
# HOOKS:
# -----------------------------------------------------------------------------
def before_all(context):
global didstartsonar
print(BRIGHT + "\nSetting up the test environment" + RESET_ALL)
if is_webui_up():
API = TestRailApiUtils(URL)
API.user = EMAIL
API.password = PASSWORD
# Main
if publish_results(
API,
TESTCASES,
run_id=ARGUMENTS.run_id,
plan_id=ARGUMENTS.plan_id,
version=VERSION,
publish_blocked=PUBLISH_BLOCKED):
print(Fore.GREEN + 'OK' + Fore.RESET)
sys.exit()
else:
print(Fore.LIGHTRED_EX + 'ERROR' + Fore.RESET)
sys.exit(1)
def _colorama(*args, **kwargs):
"""Temporarily enable colorama."""
colorama.init(*args, **kwargs)
try:
yield
finally:
colorama.deinit()
def format_string(value, color):
Color.__initialize()
colors = {"red": Fore.RED, "green": Fore.GREEN, "yellow": Fore.YELLOW, "blue": Fore.BLUE}
return "{style}{color}{value}{reset}".format(style=Style.BRIGHT, color=colors[color],
value=value, reset=Style.RESET_ALL)
def pretty_print_testcase(testcase, error=''):
""" Pretty print a testcase """
if error:
msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \
Fore.MAGENTA + '{status}' + Fore.RESET + '\t' + \
'{name}\t=> ' + str(error)
elif testcase['status'] == 'PASS':
msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \
Fore.LIGHTGREEN_EX + '{status}' + Fore.RESET + '\t' + \
'{name}\t'
else:
msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \
Fore.LIGHTRED_EX + '{status}' + Fore.RESET + '\t' + \
'{name}\t'
print(msg_template.format(**testcase), end=Style.RESET_ALL)
result, _ = capsys.readouterr()
# Ansible Environment
title = [
colorama.Back.WHITE,
colorama.Style.BRIGHT,
colorama.Fore.BLACK,
'DEBUG: ANSIBLE ENVIRONMENT',
colorama.Fore.RESET,
colorama.Back.RESET,
colorama.Style.RESET_ALL,
]
print(''.join(title))
data = [
colorama.Fore.BLACK,
colorama.Style.BRIGHT,
util.safe_dump({'ANSIBLE_FOO': 'foo', 'ANSIBLE_BAR': 'bar'}),
colorama.Style.RESET_ALL,
colorama.Fore.RESET,
]
print(''.join(data))
# Molecule Environment
title = [
colorama.Back.WHITE,
colorama.Style.BRIGHT,
colorama.Fore.BLACK,
'DEBUG: MOLECULE ENVIRONMENT',
colorama.Fore.RESET,
colorama.Back.RESET,
colorama.Style.RESET_ALL,
]
Fore.BLUE + 'TEST' + Style.RESET_ALL,
colored('TEST', 'blue'),
])
def test_colors(outer_widths, left, intersect, right, title, expected):
"""Test with color title characters.
:param iter outer_widths: List of integers representing column widths with padding.
:param str left: Left border.
:param str intersect: Column separator.
:param str right: Right border.
:param title: Title in border with color codes.
:param str expected: Expected output.
"""
if left and right:
expected = left + expected + right
actual = build_border(outer_widths, '-', left, intersect, right, title=title)
assert ''.join(actual) == expected
import userinterface
import colorama
rig = eightbyeight.EightByEightTestRig()
while True:
message = """
_____ ______ _______ __
| __ \| ____| /\ | __ \ \ / /
| |__) | |__ / \ | | | \ \_/ /
| _ /| __| / /\ \ | | | |\ /
| | \ \| |____ / ____ \| |__| | | |
|_| \_\______/_/ \_\_____/ |_|
"""
userinterface.interface.DisplayMessage(message, fgcolor=colorama.Fore.BLUE)
while (not rig.testrig.readStartButton()):
pass
rig.testrig.setLED("pass", True)
rig.testrig.setLED("fail", True)
#runner = unittest.TextTestRunner(failfast = True)
#runner = redgreenunittest.TextTestRunner(failfast = True)
runner = blinkinlabsunittest.BlinkinlabsTestRunner(failfast = True)
result = runner.run(unittest.TestLoader().loadTestsFromTestCase(EightByEightTests))
if len(result.failures) > 0 or len(result.errors) > 0:
rig.testrig.setLED("pass", False)
rig.testrig.setLED("fail", True)
#runner = unittest.TextTestRunner(failfast = True)
#runner = redgreenunittest.TextTestRunner(failfast = True)
runner = blinkinlabsunittest.BlinkinlabsTestRunner(failfast = True)
result = runner.run(unittest.TestLoader().loadTestsFromTestCase(EightByEightTests))
if len(result.failures) > 0 or len(result.errors) > 0:
rig.testrig.setLED("pass", False)
rig.testrig.setLED("fail", True)
message = """ ______ _____ _
| ____/\ |_ _| |
| |__ / \ | | | |
| __/ /\ \ | | | |
| | / ____ \ _| |_| |____
|_|/_/ \_\_____|______|"""
userinterface.interface.DisplayMessage(message, fgcolor=colorama.Fore.BLACK, bgcolor=colorama.Back.RED)
else:
rig.testrig.setLED("pass", True)
rig.testrig.setLED("fail", False)
message = """ ____ _ __
/ __ \ | | / /
| | | | | |/ /
| | | | | |
| |__| | | |\ \\
\____/ |_| \_\\"""
userinterface.interface.DisplayMessage(message, fgcolor=colorama.Fore.BLACK, bgcolor=colorama.Back.GREEN)
time.sleep(1)