本文整理汇总了Python中pygments.formatters.TerminalFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python formatters.TerminalFormatter方法的具体用法?Python formatters.TerminalFormatter怎么用?Python formatters.TerminalFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.formatters
的用法示例。
在下文中一共展示了formatters.TerminalFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_source_method
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def get_source_method(self, m):
"""
Return the Java source of a single method
:param m: `EncodedMethod` Object
:return:
"""
class_name = m.get_class_name()
method_name = m.get_name()
if class_name not in self.classes:
return ""
lexer = get_lexer_by_name("java", stripall=True)
lexer.add_filter(MethodFilter(method_name=method_name))
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
示例2: color_stack_trace
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def color_stack_trace():
def excepthook(type_, value, trace):
text = ''.join(traceback.format_exception(type_, value, trace))
try:
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter
lexer = get_lexer_by_name('pytb', stripall=True)
formatter = TerminalFormatter()
sys.stderr.write(highlight(text, lexer, formatter))
except Exception:
sys.stderr.write(text)
sys.stderr.write('Failed to colorize the traceback.')
sys.excepthook = excepthook
setup_thread_excepthook()
示例3: get_all
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def get_all(self, class_name):
if class_name not in self.classes:
return ""
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
示例4: display_source
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def display_source(self, m):
result = self.get_source_method(m)
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(result, lexer, formatter)
print(result)
示例5: display_all
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def display_all(self, _class):
result = self.get_source_class(_class)
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(result, lexer, formatter)
print(result)
示例6: format_dict
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_dict(tx):
from pygments import highlight, lexers, formatters
json_raw = json.dumps(tx, sort_keys=True, indent=4)
return highlight(
bytes(json_raw, "UTF-8"), lexers.JsonLexer(), formatters.TerminalFormatter()
)
示例7: format_json_color
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_json_color(obj):
from pygments import highlight, lexers, formatters
return highlight(format_json(obj), lexers.JsonLexer(), formatters.TerminalFormatter()) # pylint: disable=no-member
示例8: format_yaml_color
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_yaml_color(obj):
from pygments import highlight, lexers, formatters
return highlight(format_yaml(obj), lexers.YamlLexer(), formatters.TerminalFormatter()) # pylint: disable=no-member
示例9: syntax_highlight_tb
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def syntax_highlight_tb(tb_text):
"""Syntax highlights the traceback so that's a little easier to parse."""
lexer = lexers.get_lexer_by_name("pytb", stripall=True)
return highlight(tb_text, lexer, formatters.TerminalFormatter())
示例10: colorize_json
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def colorize_json(data):
try:
from pygments import highlight, lexers, formatters
if PY3:
if isinstance(data, bytes):
data = data.decode('UTF-8')
else:
if not isinstance(data, unicode):
data = unicode(data, 'UTF-8')
colorful_json = highlight(data,
lexers.JsonLexer(),
formatters.TerminalFormatter())
return colorful_json
except ModuleNotFoundError:
return data
示例11: print_json
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def print_json(data):
#colorful_json = highlight(unicode(format_json(data), 'UTF-8'),
# lexers.JsonLexer(),
# formatters.TerminalFormatter())
pprint(colorize_json(format_json(data)))
示例12: log_json
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def log_json(json, header="", also_console=True, sort_keys=False):
json = dumps(
json,
ensure_ascii=False,
indent=4,
separators=(",", ": "),
sort_keys=sort_keys,
)
logger.info("{}\n{}".format(header, json)) # no coloring for log.html
if also_console:
json_data = highlight(
json, lexers.JsonLexer(), formatters.TerminalFormatter()
)
logger.console("{}\n{}".format(header, json_data), newline=False)
return json
示例13: prettify_json
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def prettify_json(some_text):
try:
return highlight(
json.dumps(json.loads(some_text), indent=4),
lexers.JsonLexer(),
formatters.TerminalFormatter())
except:
return some_text
示例14: pprint
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def pprint(value):
formatted_value = highlight(
json.dumps(
value,
sort_keys=True,
indent=4,
separators=(',', ': ')
),
JsonLexer(),
TerminalFormatter(bg='dark')
)
print(formatted_value)
示例15: print_func
# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def print_func(func):
print("--- Code start ---")
code = "".join(inspect.getsourcelines(func)[0][1:])
print(highlight(code, PythonLexer(), TerminalFormatter(bg='dark')))
print("--- Code end ---")