def col(s, c, bg=0, no_reset=0):
    """
    print col('foo', 124) -> red 'foo' on the terminal
    c = color, s the value to colorize """
    reset = reset_col
    if no_reset:
        reset = ''
    for _strt, _end, _col in ((code_start, code_end, H2),
                              (stng_start, stng_end, H2),
                              (emph_start, emph_end, H3)):
        if _strt in s:
            # inline code:
            s = s.replace(_strt, col('', _col, bg=background, no_reset=1))
            s = s.replace(_end , col('', c, no_reset=1))

    s =  '\033[38;5;%sm%s%s' % (c, s, reset)
    if bg:
        pass
        #s = col_bg(bg) + s
    return s
def col ( s , c , bg = 0 , no_reset = 0 ) : reset = reset_col if no_reset : reset = '' for _strt , _end , _col in ( ( code_start , code_end , H2 ) , ( stng_start , stng_end , H2 ) , ( emph_start , emph_end , H3 ) ) : if _strt in s : s = s . replace ( _strt , col ( '' , _col , bg = background , no_reset = 1 ) ) s = s . replace ( _end , col ( '' , c , no_reset = 1 ) ) s = '\033[38;5;%sm%s%s' % ( c , s , reset ) if bg : pass return s
print col('foo', 124) -> red 'foo' on the terminal
    c = color, s the value to colorize