How to use the termcolor.COLORS function in termcolor

To help you get started, we’ve selected a few termcolor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zaufi / pluggable-output-processor / outproc / config.py View on Github external
# Handle special value 'none' as color inhibitor
        if 'none' in colors:
            return result

        if with_reset:
            result = '\x1b[0m'

        for c in colors:
            #
            result += '\x1b['
            #
            if c == 'reset':
                result += '0'
            elif c == 'normal':
                result += '38'
            elif c in termcolor.COLORS:
                result += str(termcolor.COLORS[c])
            elif c in termcolor.ATTRIBUTES:
                result += str(termcolor.ATTRIBUTES[c])
            elif c in termcolor.HIGHLIGHTS:
                result += str(termcolor.HIGHLIGHTS[c])
            elif self._RGB_COLOR_SPEC_RE.match(c):
                # BUG Fucking Python! Why not to assign and check a variable inside of `if`
                # TODO Avoid double regex match
                match = self._RGB_COLOR_SPEC_RE.search(c)
                try:
                    r = self._validate_rgb_component(int(match.group(1)))
                    g = self._validate_rgb_component(int(match.group(2)))
                    b = self._validate_rgb_component(int(match.group(3)))
                    if r <= 5 and g <= 5 and b <= 5:
                        index = self._rgb_to_index(r, g, b)
                        result += '38;5;' + str(index)
github eegsynth / eegsynth / lib / EEGsynth.py View on Github external
def __init__(self, name=None):
        self.name = name
        colors = list(termcolor.COLORS.keys()) # prevent RuntimeError: dictionary changed size during iteration
        # add reverse and bright color
        for color in colors:
            termcolor.COLORS['reverse_'+color] = termcolor.COLORS[color]+10
            termcolor.COLORS['bright_'+color] = termcolor.COLORS[color]+60
        # for color in termcolor.COLORS.keys():
github cshuaimin / aiodl / aiodl / utils.py View on Github external
import asyncio
import aiohttp
import random
import functools
import socket

from contextlib import contextmanager
from termcolor import colored, COLORS
from tqdm import tqdm


colors = list(COLORS)


def print_colored_kv(k, v):
    tqdm.write(
        colored('  ' + k + ': ', color=random.choice(colors), attrs=['bold']) +
        colored(v, color='white', attrs=['bold'])
    )


class AiodlQuitError(Exception):
    'Something caused aiodl to quit.'


class ClosedRange:
    def __init__(self, begin, end):
        self.begin = begin
github alttch / eva3 / lib / eva / client / cli.py View on Github external
def safe_colored(text, color=None, on_color=None, attrs=None, rlsafe=False):
    if os.getenv('ANSI_COLORS_DISABLED') is None:
        fmt_str = '\033[%dm'
        if rlsafe:
            fmt_str = '\001' + fmt_str + '\002'
        fmt_str += '%s'
        if color is not None:
            text = fmt_str % (termcolor.COLORS[color], text)

        if on_color is not None:
            text = fmt_str % (termcolor.HIGHLIGHTS[on_color], text)

        if attrs is not None:
            for attr in attrs:
                text = fmt_str % (termcolor.ATTRIBUTES[attr], text)

        if rlsafe:
            text += '\001' + termcolor.RESET + '\002'
        else:
            text += termcolor.RESET
    return text