當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。