def display(rxs, s): spanlists = [] colors = [] for i, rx in enumerate(rxs): spanlist = [] for m in re.finditer(rx, s): spanlist.append(m.span()) spanlists.append(spanlist) colors.append(get_highlighter(i)) if reverse: colors.reverse() s = highlight_string(s, *spanlists, colors=colors) for (i, rx) in enumerate(rxs): color = get_highlighter(i) color = colorize(color.__name__.ljust(10), color) write_out('Regex %s: %s %s\n' % (i, color, rx)) write_out(s)
def demo_color(): width = 10 lst = [] lst.extend([[], ['>>> Without colors'], []]) line = [] line.append(colorize("Standard".ljust(width), None)) line.append(colorize("Bold".ljust(width), None, bold=True)) line.append(colorize("Reverse".ljust(width), None, reverse=True)) line.append(colorize("Bold & Rev".ljust(width), None, bold=True, reverse=True)) # noqa lst.append(line) lst.extend([[], ['>>> Using colors'], []]) for color in Colors.iter(): line = [] line.append(colorize(color.__name__.ljust(width), color)) line.append(colorize(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, reverse=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, bold=True, reverse=True)) # noqa lst.append(line) lst.extend([[], ['>>> Using highlighting colors'], []]) for color in Colors.iter(): color = get_highlighter(color.id) line = [] line.append(colorize(color.__name__.ljust(width), color)) line.append(colorize(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, reverse=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, bold=True, reverse=True)) # noqa lst.append(line) for line in lst: for item in line: write_out('%s ' % item) write_out("\n")