def colorizer(tag, text):
    label, hilight = tag
    color = 1 + hash(label) % 7
    for line in text.split('\n'):
        if hilight:
            yield '\033[30;4%dm[%s]\033[0;1;3%dm %s\033[0m\n' % (color, label, color, line)
        else:
            yield '\033[3%dm[%s] %s\033[0m\n' % (color, label, line)
Basic ANSI colorized output - host hash value map to 7-color palette, stderr bold
dataset/ETHPy150Open radssh/radssh/radssh/console.py/colorizer