本文整理汇总了Python中colorama.Back方法的典型用法代码示例。如果您正苦于以下问题:Python colorama.Back方法的具体用法?Python colorama.Back怎么用?Python colorama.Back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colorama
的用法示例。
在下文中一共展示了colorama.Back方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_color
# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Back [as 别名]
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
示例2: colorize
# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Back [as 别名]
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
示例3: _back
# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Back [as 别名]
def _back(self):
if self.allow_terminal_colors:
import colorama
return colorama.Back
else:
return _ColoramaStub()
示例4: color
# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Back [as 别名]
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