当前位置: 首页>>代码示例>>Python>>正文


Python formatters.Terminal256Formatter方法代码示例

本文整理汇总了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)) 
开发者ID:kellyjonbrazil,项目名称:jc,代码行数:18,代码来源:cli.py

示例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() 
开发者ID:crowsonkb,项目名称:style_transfer,代码行数:24,代码来源:style_transfer.py

示例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 
开发者ID:takeshixx,项目名称:deen,代码行数:25,代码来源:arm.py

示例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') 
开发者ID:samuelcolvin,项目名称:python-devtools,代码行数:11,代码来源:prettier.py

示例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")) 
开发者ID:skorokithakis,项目名称:tbvaccine,代码行数:31,代码来源:tbv.py

示例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 
开发者ID:exoscale,项目名称:cs,代码行数:12,代码来源:__init__.py

示例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)) 
开发者ID:nstack,项目名称:stackhut,代码行数:6,代码来源:run_commands.py

示例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) 
开发者ID:nstack,项目名称:stackhut,代码行数:35,代码来源:run_commands.py

示例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) 
开发者ID:MichaelGrupp,项目名称:evo,代码行数:8,代码来源:main_config.py

示例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 
开发者ID:takeshixx,项目名称:deen,代码行数:29,代码来源:x86.py

示例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())) 
开发者ID:jeanfeydy,项目名称:lddmm-ot,代码行数:9,代码来源:show_code.py

示例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) 
开发者ID:henriquebastos,项目名称:sqlformatter,代码行数:14,代码来源:sqlformatter.py

示例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 
开发者ID:diego-treitos,项目名称:ansible-inventory,代码行数:38,代码来源:__init__.py


注:本文中的pygments.formatters.Terminal256Formatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。