dotfiles/script-resources/welcome/colors.py

23 lines
608 B
Python
Raw Normal View History

2018-08-09 10:35:09 +00:00
from colorama import Fore, Style, ansi
2018-08-09 10:35:09 +00:00
COLORS = [ansi.code_to_chars(30 + color_index) for color_index in range(0, 8)]
def colored(string, *colors):
return "".join(colors + (string, Style.RESET_ALL))
2018-08-09 10:35:09 +00:00
def bright_colored(string, *colors):
return "".join(colors + (Style.BRIGHT, string, Style.RESET_ALL))
2018-08-09 10:35:09 +00:00
def colorize_percent(percent, warning, critical, inverse=False):
COLORS = [Fore.GREEN, Fore.YELLOW, Fore.RED]
2018-08-09 10:35:09 +00:00
color_index = 0 if percent < warning else 1 if percent < critical else 2
if inverse:
color_index = 2 - color_index
2018-08-09 10:35:09 +00:00
return colored("%.2f%%" % percent, COLORS[color_index])