本文整理汇总了Python中pygments.console.codes方法的典型用法代码示例。如果您正苦于以下问题:Python console.codes方法的具体用法?Python console.codes怎么用?Python console.codes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.console
的用法示例。
在下文中一共展示了console.codes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: color_string
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import codes [as 别名]
def color_string(self):
attrs = []
if self.fg is not None:
if self.fg in ansicolors:
esc = codes[self.fg[5:]]
if ';01m' in esc:
self.bold = True
# extract fg color code.
attrs.append(esc[2:4])
else:
attrs.extend(("38", "5", "%i" % self.fg))
if self.bg is not None:
if self.bg in ansicolors:
esc = codes[self.bg[5:]]
# extract fg color code, add 10 for bg.
attrs.append(str(int(esc[2:4])+10))
else:
attrs.extend(("48", "5", "%i" % self.bg))
if self.bold:
attrs.append("01")
if self.underline:
attrs.append("04")
return self.escape(attrs)
示例2: color_string
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import codes [as 别名]
def color_string(self):
attrs = []
if self.fg is not None:
if self.fg in ansicolors:
esc = codes[self.fg.replace('ansi','')]
if ';01m' in esc:
self.bold = True
# extract fg color code.
attrs.append(esc[2:4])
else:
attrs.extend(("38", "5", "%i" % self.fg))
if self.bg is not None:
if self.bg in ansicolors:
esc = codes[self.bg.replace('ansi','')]
# extract fg color code, add 10 for bg.
attrs.append(str(int(esc[2:4])+10))
else:
attrs.extend(("48", "5", "%i" % self.bg))
if self.bold:
attrs.append("01")
if self.underline:
attrs.append("04")
if self.italic:
attrs.append("03")
return self.escape(attrs)
示例3: test_console_ansiformat
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import codes [as 别名]
def test_console_ansiformat():
f = console.ansiformat
c = console.codes
all_attrs = f('+*_blue_*+', 'text')
assert c['blue'] in all_attrs and c['blink'] in all_attrs
assert c['bold'] in all_attrs and c['underline'] in all_attrs
assert c['reset'] in all_attrs
assert raises(KeyError, f, '*mauve*', 'text')
示例4: test_console_functions
# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import codes [as 别名]
def test_console_functions():
assert console.reset_color() == console.codes['reset']
assert console.colorize('blue', 'text') == \
console.codes['blue'] + 'text' + console.codes['reset']