def demo_color_v2(): width = 10 lst = [] lst.extend([[], ['>>> Without colors'], []]) line = [] line.append(colorize_v2("Standard".ljust(width), None)) line.append(colorize_v2("Bold".ljust(width), None, bold=True)) line.append(colorize_v2("Underline".ljust(width), None, underline=True)) line.append(colorize_v2("Blink".ljust(width), None, blink=True)) line.append(colorize_v2("Reverse".ljust(width), None, reverse=True)) line.append(colorize_v2("Bold & Rev".ljust(width), None, bold=True, underline=True, reverse=True)) # noqa lst.append(line) lst.extend([[], ['>>> Using colors_v2'], []]) for color in Colors.iter(): line = [] line.append(colorize_v2(color.__name__.ljust(width), color)) line.append(colorize_v2(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, underline=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, blink=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, reverse=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, bold=True, underline=True, reverse=True)) # noqa lst.append(line) lst.extend([[], ['>>> Using highlighting colors_v2'], []]) for color in Colors.iter(): color = get_highlighter(color.id) line = [] line.append(colorize_v2(color.__name__.ljust(width), color)) line.append(colorize_v2(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, underline=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, blink=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, reverse=True)) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, bold=True, underline=True, reverse=True)) # noqa lst.append(line) for line in lst: for item in line: write_out('%s ' % item) write_out("\n")
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_highlight(reverse=False): rxs = [ '(b+).*\\1', '(c+).*\\1', '(d+).*\\1', '(e+).*\\1', ] s = """\ aaabbbcccdddeeefffeeedddcccbbbaaa fffeeedddcccbbbaaabbbcccdddeeefff """ 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) for i in range(0, len(rxs) + 1): write_out('\n') display(rxs[:i], s)
def display_diff(s, t): (s_fmt, t_fmt) = colordiff(s, t) write_out('>>> %s\n' % s_fmt) write_out(' %s\n\n' % t_fmt)