本文整理匯總了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']