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


Python formatted_text.PygmentsTokens方法代码示例

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


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

示例1: print_lexer

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def print_lexer(
    body: str, lexer: Lexer, label: str = None, prefix: str = None, indent: int = None
):
    if COLORIZE:
        prefix_str = prefix + " " if prefix else ""
        if prefix_str or indent:
            prefix_body = prefix_str + " " * (indent or 0)
            lexer.add_filter(PrefixFilter(prefix=prefix_body))
        tokens = list(pygments.lex(body, lexer=lexer))
        if label:
            fmt_label = [("fg:ansimagenta", label)]
            if prefix_str:
                fmt_label.insert(0, ("", prefix_str))
            print_formatted(FormattedText(fmt_label))
        print_formatted(PygmentsTokens(tokens))
    else:
        print_ext(body, label=label, prefix=prefix) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:19,代码来源:utils.py

示例2: _get_toolbar_tokens

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def _get_toolbar_tokens(is_connected, servers, info):
    if is_connected:
        hosts = ', '.join(re.sub(r'^https?:\/\/', '', a) for a in servers)
        return PygmentsTokens([
            (Token.Toolbar.Status.Key, 'USER: '),
            (Token.Toolbar.Status, info.user or '--'),
            (Token.Toolbar.Status, ' | '),
            (Token.Toolbar.Status.Key, 'SCHEMA: '),
            (Token.Toolbar.Status, info.schema or 'doc'),
            (Token.Toolbar.Status, ' | '),
            (Token.Toolbar.Status.Key, 'CLUSTER: '),
            (Token.Toolbar.Status, info.cluster or '--'),
            (Token.Toolbar.Status, ' | '),
            (Token.Toolbar.Status.Key, 'HOSTS: '),
            (Token.Toolbar.Status, hosts)
        ])
    else:
        return PygmentsTokens([(Token.Toolbar.Status, 'not connected')]) 
开发者ID:crate,项目名称:crash,代码行数:20,代码来源:repl.py

示例3: print_packets

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def print_packets(path: list, nodes: dict) -> None:
    tokens = []
    for e in path[:-1]:
        node = nodes[e.dst]
        p = node.render()
        line = '{} = {}'.format(node.name.replace('-', '_'), repr(p))
        tokens.extend(list(pygments.lex(line, lexer=Python3Lexer())))

    # p = self.fuzz_node.render()
    node = nodes[path[-1].dst]
    p = node.render()
    line = '{} = {}'.format(node.name.replace('-', '_'), repr(p))

    print(pygments.highlight(line, Python3Lexer(), Terminal256Formatter(style='rrt')))

    # tokens.extend(list(pygments.lex(line, lexer=Python3Lexer())))
    # style = style_from_pygments_cls(get_style_by_name('colorful'))
    # print_formatted_text(PygmentsTokens(tokens), style=style)


# --------------------------------------------------------------- # 
开发者ID:nccgroup,项目名称:fuzzowski,代码行数:23,代码来源:printers.py

示例4: in_prompt

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def in_prompt(self):
        return PygmentsTokens(self.prompts.in_prompt_tokens()) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:4,代码来源:ipython.py

示例5: in2_prompt

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def in2_prompt(self, width):
        return PygmentsTokens(self.prompts.continuation_prompt_tokens()) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:4,代码来源:ipython.py

示例6: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def main():
    # Printing a manually constructed list of (Token, text) tuples.
    text = [
        (Token.Keyword, "print"),
        (Token.Punctuation, "("),
        (Token.Literal.String.Double, '"'),
        (Token.Literal.String.Double, "hello"),
        (Token.Literal.String.Double, '"'),
        (Token.Punctuation, ")"),
        (Token.Text, "\n"),
    ]

    print_formatted_text(PygmentsTokens(text))

    # Printing the output of a pygments lexer.
    tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer()))
    print_formatted_text(PygmentsTokens(tokens))

    # With a custom style.
    style = Style.from_dict(
        {
            "pygments.keyword": "underline",
            "pygments.literal.string": "bg:#00ff00 #ffffff",
        }
    )
    print_formatted_text(PygmentsTokens(tokens), style=style) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:28,代码来源:pygments-tokens.py

示例7: print_python

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def print_python(path: list) -> None:
    tokens = []
    block_code = path_to_python(path)
    print(pygments.highlight(block_code, Python3Lexer(), Terminal256Formatter(style='rrt')))

    # tokens.extend(list(pygments.lex(block_code, lexer=Python3Lexer())))
    # print_formatted_text(PygmentsTokens(tokens))

# --------------------------------------------------------------- # 
开发者ID:nccgroup,项目名称:fuzzowski,代码行数:11,代码来源:printers.py

示例8: print_poc

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def print_poc(target: Target, path: list,
              receive_data_after_each_request, receive_data_after_fuzz) -> None:
    tokens = []

    exploit_code = get_exploit_code(target, path, receive_data_after_each_request, receive_data_after_fuzz)
    print(pygments.highlight(exploit_code, Python3Lexer(), Terminal256Formatter(style='rrt')))

    # tokens.extend(list(pygments.lex(exploit_code, lexer=Python3Lexer())))
    # print_formatted_text(PygmentsTokens(tokens))

# --------------------------------------------------------------- # 
开发者ID:nccgroup,项目名称:fuzzowski,代码行数:13,代码来源:printers.py

示例9: display_bibs

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import PygmentsTokens [as 别名]
def display_bibs(labels, bibs, meta=False):
  r"""
  Display a list of bib entries on screen with flying colors.

  Parameters
  ----------
  labels: List of Strings
      Header labels to show above each Bib() entry.
  bibs: List of Bib() objects
      BibTeX entries to display.
  meta: Bool
      If True, also display the meta-information.

  Examples
  --------
  >>> import bibmanager.bib_manager as bm
  >>> e1 = '''@Misc{JonesEtal2001scipy,
         author = {Eric Jones and Travis Oliphant and Pearu Peterson},
         title  = {{SciPy}: Open source scientific tools for {Python}},
         year   = {2001},
       }'''
  >>> e2 = '''@Misc{Jones2001,
         author = {Eric Jones and Travis Oliphant and Pearu Peterson},
         title  = {SciPy: Open source scientific tools for Python},
         year   = {2001},
       }'''
  >>> bibs = [bm.Bib(e1), bm.Bib(e2)]
  >>> bm.display_bibs(["DATABASE:\n", "NEW:\n"], bibs)
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  DATABASE:
  @Misc{JonesEtal2001scipy,
         author = {Eric Jones and Travis Oliphant and Pearu Peterson},
         title  = {{SciPy}: Open source scientific tools for {Python}},
         year   = {2001},
       }

  NEW:
  @Misc{Jones2001,
         author = {Eric Jones and Travis Oliphant and Pearu Peterson},
         title  = {SciPy: Open source scientific tools for Python},
         year   = {2001},
       }
  """
  style = prompt_toolkit.styles.style_from_pygments_cls(
              pygments.styles.get_style_by_name(cm.get('style')))
  if labels is None:
      labels = ["" for _ in bibs]
  tokens = [(Token.Comment, u.BANNER)]
  for label,bib in zip(labels, bibs):
      tokens += [(Token.Text, label)]
      if meta:
          tokens += [(Token.Comment, bib.meta())]
      tokens += list(pygments.lex(bib.content, lexer=BibTeXLexer()))
      tokens += [(Token.Text, "\n")]
  print_formatted_text(PygmentsTokens(tokens), end="", style=style,
      output=create_output(sys.stdout)) 
开发者ID:pcubillos,项目名称:bibmanager,代码行数:58,代码来源:bib_manager.py


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