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