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