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


Python formatters.TerminalFormatter方法代码示例

本文整理汇总了Python中pygments.formatters.TerminalFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python formatters.TerminalFormatter方法的具体用法?Python formatters.TerminalFormatter怎么用?Python formatters.TerminalFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.formatters的用法示例。


在下文中一共展示了formatters.TerminalFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_source_method

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def get_source_method(self, m):
        """
        Return the Java source of a single method

        :param m: `EncodedMethod` Object
        :return:
        """
        class_name = m.get_class_name()
        method_name = m.get_name()

        if class_name not in self.classes:
            return ""

        lexer = get_lexer_by_name("java", stripall=True)
        lexer.add_filter(MethodFilter(method_name=method_name))
        formatter = TerminalFormatter()
        result = highlight(self.classes[class_name], lexer, formatter)
        return result 
开发者ID:amimo,项目名称:dcc,代码行数:20,代码来源:decompiler.py

示例2: color_stack_trace

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def color_stack_trace():

    def excepthook(type_, value, trace):
        text = ''.join(traceback.format_exception(type_, value, trace))
        try:
            from pygments import highlight
            from pygments.lexers import get_lexer_by_name
            from pygments.formatters import TerminalFormatter
            lexer = get_lexer_by_name('pytb', stripall=True)
            formatter = TerminalFormatter()
            sys.stderr.write(highlight(text, lexer, formatter))
        except Exception:
            sys.stderr.write(text)
            sys.stderr.write('Failed to colorize the traceback.')

    sys.excepthook = excepthook
    setup_thread_excepthook() 
开发者ID:danijar,项目名称:mindpark,代码行数:19,代码来源:other.py

示例3: get_all

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def get_all(self, class_name):
        if class_name not in self.classes:
            return ""

        lexer = get_lexer_by_name("java", stripall=True)
        formatter = TerminalFormatter()
        result = highlight(self.classes[class_name], lexer, formatter)
        return result 
开发者ID:amimo,项目名称:dcc,代码行数:10,代码来源:decompiler.py

示例4: display_source

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def display_source(self, m):
        result = self.get_source_method(m)

        lexer = get_lexer_by_name("java", stripall=True)
        formatter = TerminalFormatter()
        result = highlight(result, lexer, formatter)
        print(result) 
开发者ID:amimo,项目名称:dcc,代码行数:9,代码来源:decompiler.py

示例5: display_all

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def display_all(self, _class):
        result = self.get_source_class(_class)

        lexer = get_lexer_by_name("java", stripall=True)
        formatter = TerminalFormatter()
        result = highlight(result, lexer, formatter)
        print(result) 
开发者ID:amimo,项目名称:dcc,代码行数:9,代码来源:decompiler.py

示例6: format_dict

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_dict(tx):
    from pygments import highlight, lexers, formatters

    json_raw = json.dumps(tx, sort_keys=True, indent=4)
    return highlight(
        bytes(json_raw, "UTF-8"), lexers.JsonLexer(), formatters.TerminalFormatter()
    ) 
开发者ID:bitshares,项目名称:uptick,代码行数:9,代码来源:ui.py

示例7: format_json_color

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_json_color(obj):
    from pygments import highlight, lexers, formatters
    return highlight(format_json(obj), lexers.JsonLexer(), formatters.TerminalFormatter())  # pylint: disable=no-member 
开发者ID:microsoft,项目名称:knack,代码行数:5,代码来源:output.py

示例8: format_yaml_color

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def format_yaml_color(obj):
    from pygments import highlight, lexers, formatters
    return highlight(format_yaml(obj), lexers.YamlLexer(), formatters.TerminalFormatter())  # pylint: disable=no-member 
开发者ID:microsoft,项目名称:knack,代码行数:5,代码来源:output.py

示例9: syntax_highlight_tb

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def syntax_highlight_tb(tb_text):
    """Syntax highlights the traceback so that's a little easier to parse."""
    lexer = lexers.get_lexer_by_name("pytb", stripall=True)
    return highlight(tb_text, lexer, formatters.TerminalFormatter()) 
开发者ID:quora,项目名称:asynq,代码行数:6,代码来源:debug.py

示例10: colorize_json

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def colorize_json(data):
    try:
        from pygments import highlight, lexers, formatters
        if PY3:
            if isinstance(data, bytes):
                data = data.decode('UTF-8')
        else:
            if not isinstance(data, unicode):
                data = unicode(data, 'UTF-8')
        colorful_json = highlight(data,
                                  lexers.JsonLexer(),
                                  formatters.TerminalFormatter())
        return colorful_json
    except ModuleNotFoundError:
        return data 
开发者ID:CITGuru,项目名称:PyInquirer,代码行数:17,代码来源:utils.py

示例11: print_json

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def print_json(data):
    #colorful_json = highlight(unicode(format_json(data), 'UTF-8'),
    #                          lexers.JsonLexer(),
    #                          formatters.TerminalFormatter())
    pprint(colorize_json(format_json(data))) 
开发者ID:CITGuru,项目名称:PyInquirer,代码行数:7,代码来源:utils.py

示例12: log_json

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def log_json(json, header="", also_console=True, sort_keys=False):
        json = dumps(
            json,
            ensure_ascii=False,
            indent=4,
            separators=(",", ": "),
            sort_keys=sort_keys,
        )
        logger.info("{}\n{}".format(header, json))  # no coloring for log.html
        if also_console:
            json_data = highlight(
                json, lexers.JsonLexer(), formatters.TerminalFormatter()
            )
            logger.console("{}\n{}".format(header, json_data), newline=False)
        return json 
开发者ID:asyrjasalo,项目名称:RESTinstance,代码行数:17,代码来源:__init__.py

示例13: prettify_json

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def prettify_json(some_text):
    try:
        return highlight(
            json.dumps(json.loads(some_text), indent=4),
            lexers.JsonLexer(),
            formatters.TerminalFormatter())
    except:
        return some_text 
开发者ID:akamai-threat-research,项目名称:mqtt-pwn,代码行数:10,代码来源:__init__.py

示例14: pprint

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def pprint(value):
    formatted_value = highlight(
        json.dumps(
            value,
            sort_keys=True,
            indent=4,
            separators=(',', ': ')
        ),
        JsonLexer(),
        TerminalFormatter(bg='dark')
    )
    print(formatted_value) 
开发者ID:jsoucheiron,项目名称:pttdm,代码行数:14,代码来源:pttdm.py

示例15: print_func

# 需要导入模块: from pygments import formatters [as 别名]
# 或者: from pygments.formatters import TerminalFormatter [as 别名]
def print_func(func):
    print("--- Code start ---")
    code = "".join(inspect.getsourcelines(func)[0][1:])
    print(highlight(code, PythonLexer(), TerminalFormatter(bg='dark')))
    print("--- Code end ---") 
开发者ID:jsoucheiron,项目名称:pttdm,代码行数:7,代码来源:pttdm.py


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