Exemplo n.º 1
0
def colourise(line, grep=False, match_only=True):
    m = search(line)
    if m:
        s = [s.lower() for s in m]
        colour_name = 0

        if match_only:
            matches = re.finditer(re_pattern, line)
            for m in reversed(list(matches)):
                if m.group(1).lower() in list(level_map.keys()):
                    colour_name = level_map[m.group(1).lower()]
                line = line[0:m.start()] + colour(*colour_name) + line[m.start():m.end()] + code(0) + line[m.end():len(line)] + code(0)
            return line
        else:
            for level in list(level_map.keys()):
                if level in s:
                    colour_name = level_map[level]
                    break
            return colour(*colour_name) + line + code(0)
    else:
        return '' if grep else line
Exemplo n.º 2
0
def test_two_colours():
    assert '\x1b[30;101m' == colour('black', 'bright red')
Exemplo n.º 3
0
def test_empty_colours():
    assert '' == colour('', '')
    assert '\x1b[31m' == colour('red', '')
    assert '\x1b[42m' == colour('', 'green')
Exemplo n.º 4
0
def test_colour():
    assert '\x1b[31m' == colour('RED')