def colored(text, colors):
    """Format text with ANSI color code, eg. '\033[31;44;1m' + text + '\033[0m'

    - colors: a list of color keywords from::

        Foreground color keywords:
            black, red, green, yellow, blue, magenta, cyan, white.
        Background color keywords:
            on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
        Attributes:
            bold, dark, underline, blink, reverse, concealed.
    """
    ansi_color = {
        # foreground color codes
        'black':      30,
        'red':        31,
        'green':      32,
        'yellow':     33,
        'blue':       34,
        'magenta':    35,
        'cyan':       36,
        'white':      37,
        # background color codes
        'on_black':   40,
        'on_red':     41,
        'on_green':   42,
        'on_yellow':  43,
        'on_blue':    44,
        'on_magenta': 45,
        'on_cyan':    46,
        'on_white':   47,
        # attributes:
        'bold':        1,
        'dark':        2,
        'underline':   4,
        'blink':       5,
        'reverse':     7,
        'concealed':   8
    }

    if isinstance(colors, str):
        colors = [colors]
    color_code = ';'.join([str(ansi_color[x]) for x in colors if x in ansi_color])
    if color_code:
        return '\033[%sm%s\033[0m' % (color_code, text)
    else:
        return text