Python colorama.Back() Examples

The following are 6 code examples of colorama.Back(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module colorama , or try the search function .
Example #1
Source File: io.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def on_color(color, string):
    s = _convert_to_string(string)
    if term_is_colorable():
        colorama.init()
        color = _remap_color(color)
        color_code = getattr(colorama.Back, color.upper())
        return color_code + s + colorama.Back.RESET
    else:
        return s 
Example #2
Source File: termcolors.py    From pipenv with MIT License 5 votes vote down vote up
def colorize(text, fg=None, bg=None, attrs=None):
    if os.getenv("ANSI_COLORS_DISABLED") is None:
        style = "NORMAL"
        if attrs is not None and not isinstance(attrs, list):
            _attrs = []
            if isinstance(attrs, six.string_types):
                _attrs.append(attrs)
            else:
                _attrs = list(attrs)
            attrs = _attrs
        if attrs and "bold" in attrs:
            style = "BRIGHT"
            attrs.remove("bold")
        if fg is not None:
            fg = fg.upper()
            text = to_native_string("%s%s%s%s%s") % (
                to_native_string(getattr(colorama.Fore, fg)),
                to_native_string(getattr(colorama.Style, style)),
                to_native_string(text),
                to_native_string(colorama.Fore.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if bg is not None:
            bg = bg.upper()
            text = to_native_string("%s%s%s%s") % (
                to_native_string(getattr(colorama.Back, bg)),
                to_native_string(text),
                to_native_string(colorama.Back.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if attrs is not None:
            fmt_str = to_native_string("%s[%%dm%%s%s[9m") % (chr(27), chr(27))
            for attr in attrs:
                text = fmt_str % (ATTRIBUTES[attr], text)

        text += RESET
    else:
        text = ANSI_REMOVAL_RE.sub("", text)
    return text 
Example #3
Source File: options.py    From loopy with MIT License 5 votes vote down vote up
def _back(self):
        if self.allow_terminal_colors:
            import colorama
            return colorama.Back
        else:
            return _ColoramaStub() 
Example #4
Source File: init.py    From bintut with GNU General Public License v3.0 5 votes vote down vote up
def color(text, fore='', back='', res=True):
    prefix = fore + Style.BRIGHT if fore else ''
    prefix += getattr(Back, back.upper()) if back else ''
    suffix = Style.RESET_ALL if res else ''
    return prefix + text + suffix 
Example #5
Source File: termcolors.py    From vistir with ISC License 5 votes vote down vote up
def colorize(text, fg=None, bg=None, attrs=None):
    if os.getenv("ANSI_COLORS_DISABLED") is None:
        style = "NORMAL"
        if attrs is not None and not isinstance(attrs, list):
            _attrs = []
            if isinstance(attrs, six.string_types):
                _attrs.append(attrs)
            else:
                _attrs = list(attrs)
            attrs = _attrs
        if attrs and "bold" in attrs:
            style = "BRIGHT"
            attrs.remove("bold")
        if fg is not None:
            fg = fg.upper()
            text = to_native_string("%s%s%s%s%s") % (
                to_native_string(getattr(colorama.Fore, fg)),
                to_native_string(getattr(colorama.Style, style)),
                to_native_string(text),
                to_native_string(colorama.Fore.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if bg is not None:
            bg = bg.upper()
            text = to_native_string("%s%s%s%s") % (
                to_native_string(getattr(colorama.Back, bg)),
                to_native_string(text),
                to_native_string(colorama.Back.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if attrs is not None:
            fmt_str = to_native_string("%s[%%dm%%s%s[9m") % (chr(27), chr(27))
            for attr in attrs:
                text = fmt_str % (ATTRIBUTES[attr], text)

        text += RESET
    else:
        text = ANSI_REMOVAL_RE.sub("", text)
    return text 
Example #6
Source File: io.py    From aws-elastic-beanstalk-cli with Apache License 2.0 5 votes vote down vote up
def on_color(color, string):
    s = _convert_to_string(string)
    if term_is_colorable():
        colorama.init()
        color = _remap_color(color)
        color_code = getattr(colorama.Back, color.upper())
        return color_code + s + colorama.Back.RESET
    else:
        return s