Python pygments.formatters 模块,Terminal256Formatter() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用pygments.formatters.Terminal256Formatter()

项目:style_transfer    作者:crowsonkb    | 项目源码 | 文件源码
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_()
项目:ddquery    作者:elinaldosoft    | 项目源码 | 文件源码
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)
项目:pinder    作者:dotwaffle    | 项目源码 | 文件源码
def pprint_color(obj):
    print highlight(pformat(obj), PythonLexer(), Terminal256Formatter(style='trac'))
项目:microProxy    作者:mike820324    | 项目源码 | 文件源码
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)
项目:lddmm-ot    作者:jeanfeydy    | 项目源码 | 文件源码
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()))
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def help_highlight(string):
        return highlight(string, HelpLexer(), Terminal256Formatter(style='monokai'))
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def python_highlight(string):
        return highlight(string, PythonLexer(encoding="Utf-8"),
                         Terminal256Formatter(style='monokai',
                                              encoding="Utf-8"))
项目:deb-python-dcos    作者:openstack    | 项目源码 | 文件源码
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()
项目:tbvaccine    作者:skorokithakis    | 项目源码 | 文件源码
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
项目:tbvaccine    作者:skorokithakis    | 项目源码 | 文件源码
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"))
项目:deploy-marathon-bluegreen    作者:softonic    | 项目源码 | 文件源码
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()