本文整理匯總了Python中pygments.formatters.Terminal256Formatter方法的典型用法代碼示例。如果您正苦於以下問題:Python formatters.Terminal256Formatter方法的具體用法?Python formatters.Terminal256Formatter怎麽用?Python formatters.Terminal256Formatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygments.formatters
的用法示例。
在下文中一共展示了formatters.Terminal256Formatter方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: json_out
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def json_out(data, pretty=False, mono=False, piped_out=False):
if not mono and not piped_out:
# set colors
class JcStyle(Style):
styles = set_env_colors()
if pretty:
print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
print(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
if pretty:
print(json.dumps(data, indent=2))
else:
print(json.dumps(data))
示例2: printargs
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def printargs():
"""Prints out all command-line parameters."""
switch = {BGColor.LIGHT: 'xcode',
BGColor.DARK: 'vim',
BGColor.UNKNOWN: 'default'}
style = switch[terminal_bg()]
pprint = print
try:
import pygments
from pygments.lexers import Python3Lexer
from pygments.formatters import Terminal256Formatter
pprint = partial(pygments.highlight, lexer=Python3Lexer(),
formatter=Terminal256Formatter(style=style),
outfile=sys.stdout)
except ImportError:
pass
print('Parameters:')
for key in sorted(ARGS):
v = repr(getattr(ARGS, key))
print('% 16s: ' % key, end='')
pprint(v)
print()
示例3: _syntax_highlighting
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def _syntax_highlighting(self, data):
try:
from pygments import highlight
from pygments.lexers import GasLexer
from pygments.formatters import TerminalFormatter, Terminal256Formatter
from pygments.styles import get_style_by_name
style = get_style_by_name('colorful')
import curses
curses.setupterm()
if curses.tigetnum('colors') >= 256:
FORMATTER = Terminal256Formatter(style=style)
else:
FORMATTER = TerminalFormatter()
# When pygments is available, we
# can print the disassembled
# instructions with syntax
# highlighting.
data = highlight(data, GasLexer(), FORMATTER)
except ImportError:
pass
finally:
data = data.encode()
return data
示例4: get_pygments
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def get_pygments():
try:
import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter
except ImportError: # pragma: no cover
return None, None, None
else:
return pygments, PythonLexer(), Terminal256Formatter(style='vim')
示例5: __init__
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def __init__(self, code_dir=None, isolate=True, show_vars=True, max_length=120):
# The directory we're interested in.
if not code_dir:
code_dir = os.getcwd()
self._code_dir = code_dir
# Whether to print interesting lines in color or not. If False,
# all lines are printed in color.
self._isolate = isolate
# Our current state.
self._state = State.no_idea
# The filename of the line we're currently printing.
self._file = None
# The buffer that we use to build up the output in.
self._buffer = ""
# Whether to print variables for stack frames.
self._show_vars = show_vars
# Max length of printed variable lines
self._max_length = max_length
self._load_config()
self.pygments_lexer = PythonLexer()
self.pygments_formatter = TerminalFormatter(style=self._config.get("style", "color_scheme"))
示例6: _format_json
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def _format_json(data, theme):
"""Pretty print a dict as a JSON, with colors if pygments is present."""
output = json.dumps(data, indent=2, sort_keys=True)
if pygments and sys.stdout.isatty():
style = get_style_by_name(theme)
formatter = Terminal256Formatter(style=style)
return pygments.highlight(output, JsonLexer(), formatter)
return output
示例7: call_service
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def call_service(self, msg):
r = stackhut_api_call('run', msg)
result = highlight(json.dumps(r, indent=4), JsonLexer(), Terminal256Formatter())
log.info("Service {} returned - \n{}".format(utils.SERVER_URL, result))
示例8: test_interactive
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def test_interactive(self, service_name):
# get the contract
contract = rpc.load_contract_file()
interfaces = contract.interfaces
log.info("Service has {} interface(s) - {}".format(len(interfaces), list(interfaces.keys())))
for i in contract.interfaces.values():
log.info("Interface '{}' has {} function(s):".
format(i.name, len(i.functions)))
for f in i.functions.values():
log.info("\t{}".format(rpc.render_signature(f)))
while True:
(iface, fname) = prompt('Enter Interface.Function to test: ').split('.')
f = contract.interface(iface).function(fname)
values = [prompt('Enter "{}" value for {}: '.format(p.type, p.name))
for p in f.params]
eval_values = [json.loads(x) for x in values]
if utils.VERBOSE:
pp_values = highlight(json.dumps(eval_values, indent=4), JsonLexer(), Terminal256Formatter())
log.debug("Calling {} with {}".format(f.full_name, pp_values))
msg = {
"service": service_name,
"request": {
"method": f.full_name,
"params": eval_values
}
}
self.call_service(msg)
示例9: log_info_dict_json
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def log_info_dict_json(data_str, colored=True):
data_str = json.dumps(data_str, indent=4, sort_keys=True)
if colored and os.name != "nt":
data_str = highlight(data_str, lexers.JsonLexer(),
formatters.Terminal256Formatter(style="monokai"))
logger.info(data_str)
示例10: _syntax_highlighting
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def _syntax_highlighting(self, data):
try:
from pygments import highlight
from pygments.lexers import NasmLexer, GasLexer
from pygments.formatters import TerminalFormatter, Terminal256Formatter
from pygments.styles import get_style_by_name
style = get_style_by_name('colorful')
import curses
curses.setupterm()
if curses.tigetnum('colors') >= 256:
FORMATTER = Terminal256Formatter(style=style)
else:
FORMATTER = TerminalFormatter()
if self.ks.syntax == keystone.KS_OPT_SYNTAX_INTEL:
lexer = NasmLexer()
else:
lexer = GasLexer()
# When pygments is available, we
# can print the disassembled
# instructions with syntax
# highlighting.
data = highlight(data, lexer, FORMATTER)
except ImportError:
pass
finally:
data = data.encode()
return data
示例11: show_code
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def show_code(func):
if type(func) is str :
code = func
else :
code = inspect.getsourcelines(func)[0]
code = ''.join(code)
print(highlight(code, PythonLexer(), Terminal256Formatter()))
示例12: __init__
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def __init__(self, *args, **kwargs):
self.highlight = kwargs.pop('highlight', True)
self.style = kwargs.pop('style', 'default')
self.parse = kwargs.pop('parse', True)
self.reindent = kwargs.pop('reindent', True)
self.keyword_case = kwargs.pop('keyword_case', 'upper')
self._lexer = SqlLexer()
self._formatter = Terminal256Formatter(style=self.style)
super(SqlFormatter, self).__init__(*args, **kwargs)
示例13: __print_vars
# 需要導入模塊: from pygments import formatters [as 別名]
# 或者: from pygments.formatters import Terminal256Formatter [as 別名]
def __print_vars( self, e_vars, pre_middle_var, pre_last_var ):
e_line = ''
e_vars_keys = []
for v in e_vars:
e_vars_keys.append( v )
if e_vars_keys:
e_vars_keys.sort()
last_key = e_vars_keys[-1]
longest_key = self.C(e_vars_keys[0]).__len__()
for v in e_vars_keys:
if self.C(v).__len__() > longest_key:
longest_key = self.C(v).__len__()
for v in e_vars_keys:
if v == last_key:
e_line+= pre_last_var
else:
e_line+= pre_middle_var
var_line = '╴%%-%ds = %%s\n' % longest_key
if isinstance( e_vars[v], dict ):
if self.color.use_colors:
from pygments import highlight, lexers, formatters
var_dict = highlight(json.dumps(e_vars[v], sort_keys=True, indent=2),
lexers.JsonLexer(),
formatters.Terminal256Formatter(style='vim'))
var_dict = var_dict.replace("\n", "\n │ │ ")
else:
var_dict = json.dumps(e_vars[v], sort_keys=True, indent=2).replace("\n", "\n │ │ ")
e_line+= var_line % (self.C(v), var_dict)
else:
e_line+= var_line % (self.C(v), e_vars[v])
return e_line