本文整理匯總了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 ---")