我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用pygments.formatters.Terminal256Formatter()。
def print_args(): """Prints out all command-line parameters.""" bg = terminal_bg() if bg is True: style = 'xcode' elif bg is False: style = 'monokai' pprint = print_ try: if bg is not None: 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_('% 14s: ' % key, end='') pprint(v) print_()
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)
def pprint_color(obj): print highlight(pformat(obj), PythonLexer(), Terminal256Formatter(style='trac'))
def colorize(lexer_name, raw_text): # pragma: no cover lexer = get_lexer_by_name(lexer_name, stripall=True) formatter = Terminal256Formatter() return highlight(raw_text, lexer, formatter)
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()))
def help_highlight(string): return highlight(string, HelpLexer(), Terminal256Formatter(style='monokai'))
def python_highlight(string): return highlight(string, PythonLexer(encoding="Utf-8"), Terminal256Formatter(style='monokai', encoding="Utf-8"))
def _highlight_json(json_value): """ :param json_value: JSON value to syntax-highlight :type json_value: dict, list, number, string, boolean, or None :returns: A string representation of the supplied JSON value, highlighted for a terminal that supports ANSI colors. :rtype: str """ return pygments.highlight( json_value, JsonLexer(), Terminal256Formatter()).strip()
def _process_var_line(self, line): """ Process a line of variables in the traceback. """ if self._show_vars is False or (self._isolate and not self._file_in_dir()): # Don't print. return False else: line = highlight(line, PythonLexer(), TerminalFormatter(style="monokai")) self._print(line.rstrip("\r\n"), max_length=self._max_length) return True
def _process_code_line(self, line): """ Process a line of code in the traceback. """ if self._isolate and not self._file_in_dir(): # Print without colors. self._print(line) else: if self._isolate: line = line[1:] self._print(">", fg="red", style="bright") line = highlight(line, PythonLexer(), TerminalFormatter(style="monokai")) self._print(line.rstrip("\r\n"))