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


Python formatted_text.FormattedText方法代码示例

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


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

示例1: print_lexer

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [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: print_ext

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def print_ext(
    *msg,
    color: str = None,
    label: str = None,
    prefix: str = None,
    indent: int = None,
    **kwargs,
):
    prefix_str = prefix or ""
    if indent:
        prefix_str += " " * indent
    if color and COLORIZE:
        msg = [(color, " ".join(map(str, msg)))]
        if prefix_str:
            msg.insert(0, ("", prefix_str + " "))
        if label:
            msg.insert(0, ("fg:ansimagenta", label + "\n"))
        print_formatted(FormattedText(msg), **kwargs)
        return
    if label:
        print(label, **kwargs)
    if prefix_str:
        msg = (prefix_str, *msg)
    print(*msg, **kwargs) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:26,代码来源:utils.py

示例3: __init__

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def __init__(self, client_state):
        def get_message():
            # If there is a message to be shown for this client, show that.
            if client_state.message:
                return client_state.message
            else:
                return ''

        def get_tokens():
            message = get_message()
            if message:
                return FormattedText([
                    ('class:message', message),
                    ('[SetCursorPosition]', ''),
                    ('class:message', ' '),
                ])
            else:
                return ''

        @Condition
        def is_visible():
            return bool(get_message())

        super(MessageToolbar, self).__init__(get_tokens) 
开发者ID:prompt-toolkit,项目名称:pymux,代码行数:26,代码来源:layout.py

示例4: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def main():
    print(HTML("\n<u>True color test.</u>"))

    for template in [
        "bg:#{0:02x}0000",  # Red.
        "bg:#00{0:02x}00",  # Green.
        "bg:#0000{0:02x}",  # Blue.
        "bg:#{0:02x}{0:02x}00",  # Yellow.
        "bg:#{0:02x}00{0:02x}",  # Magenta.
        "bg:#00{0:02x}{0:02x}",  # Cyan.
        "bg:#{0:02x}{0:02x}{0:02x}",  # Gray.
    ]:
        fragments = []
        for i in range(0, 256, 4):
            fragments.append((template.format(i), " "))

        print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_4_BIT)
        print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_8_BIT)
        print(FormattedText(fragments), color_depth=ColorDepth.DEPTH_24_BIT)
        print() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:22,代码来源:true-color-demo.py

示例5: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def main():
    style = Style.from_dict({"hello": "#ff0066", "world": "#44ff44 italic",})

    # Print using a a list of text fragments.
    text_fragments = FormattedText(
        [("class:hello", "Hello "), ("class:world", "World"), ("", "\n"),]
    )
    print(text_fragments, style=style)

    # Print using an HTML object.
    print(HTML("<hello>hello</hello> <world>world</world>\n"), style=style)

    # Print using an HTML object with inline styling.
    print(
        HTML(
            '<style fg="#ff0066">hello</style> '
            '<style fg="#44ff44"><i>world</i></style>\n'
        )
    )

    # Print using ANSI escape sequences.
    print(ANSI("\x1b[31mhello \x1b[32mworld\n")) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:24,代码来源:print-formatted-text.py

示例6: getMagicPromptLines

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def getMagicPromptLines(self, patch):
        '''
        Get the text lines from a MagicMock object from withCliPromptMock.

        Args:
            patch (mock.MagicMock): The MagicMock object from withCliPromptMock.

        Returns:
            list: A list of lines.
        '''
        self.true(patch.called, 'Assert prompt was called')
        lines = []
        for args in patch.call_args_list:
            arg = args[0][0]
            if isinstance(arg, str):
                lines.append(arg)
                continue
            if isinstance(arg, FormattedText):
                color, text = arg[0]
                lines.append(text)
                continue
            raise ValueError(f'Unknown arg: {type(arg)}/{arg}')
        return lines 
开发者ID:vertexproject,项目名称:synapse,代码行数:25,代码来源:utils.py

示例7: getMagicPromptColors

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def getMagicPromptColors(self, patch):
        '''
        Get the colored lines from a MagicMock object from withCliPromptMock.

        Args:
            patch (mock.MagicMock): The MagicMock object from withCliPromptMock.

        Returns:
            list: A list of tuples, containing color and line data.
        '''
        self.true(patch.called, 'Assert prompt was called')
        lines = []
        for args in patch.call_args_list:
            arg = args[0][0]
            if isinstance(arg, str):
                continue
            if isinstance(arg, FormattedText):
                color, text = arg[0]
                lines.append((color, text))
                continue
            raise ValueError(f'Unknown arg: {type(arg)}/{arg}')
        return lines 
开发者ID:vertexproject,项目名称:synapse,代码行数:24,代码来源:utils.py

示例8: _render_sdl

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def _render_sdl(self, sdl: str) -> None:
        desc_doc = pt_document.Document(sdl)
        lexer = pt_lexers.PygmentsLexer(eql_pygments.EdgeQLLexer)
        formatter = lexer.lex_document(desc_doc)

        for line in range(desc_doc.line_count):
            pt_shortcuts.print_formatted_text(
                pt_formatted_text.FormattedText(formatter(line)),
                style=self.style
            )
        print() 
开发者ID:edgedb,项目名称:edgedb,代码行数:13,代码来源:__init__.py

示例9: print_in_colors

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def print_in_colors(out):
    style = Style.from_dict({"cli_out": "fg:{}".format(config.cli_info_color)})
    print_formatted_text(FormattedText([("class:cli_out", str(out))]), style=style) 
开发者ID:securisec,项目名称:chepy,代码行数:5,代码来源:cli.py

示例10: banner

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def banner(animation=True):
    banners = [banner1, banner2, banner3]
    color = ColorSelected()
    text = FormattedText([
    (color.theme.banner, choice(banners)),
    (color.theme.primary, info)
    ])
    print_formatted_text(text)
    if animation:
      little_animation() 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:12,代码来源:banner.py

示例11: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def main():
    tokens = FormattedText([("fg:" + name, name + "  ") for name in NAMED_COLORS])

    print(HTML("\n<u>Named colors, using 16 color output.</u>"))
    print("(Note that it doesn't really make sense to use named colors ")
    print("with only 16 color output.)")
    print(tokens, color_depth=ColorDepth.DEPTH_4_BIT)

    print(HTML("\n<u>Named colors, use 256 colors.</u>"))
    print(tokens)

    print(HTML("\n<u>Named colors, using True color output.</u>"))
    print(tokens, color_depth=ColorDepth.TRUE_COLOR) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:15,代码来源:named-colors.py

示例12: test_formatted_text_with_style

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def test_formatted_text_with_style():
    f = _Capture()
    style = Style.from_dict({"hello": "#ff0066", "world": "#44ff44 italic",})
    tokens = FormattedText([("class:hello", "Hello "), ("class:world", "world"),])

    # NOTE: We pass the default (8bit) color depth, so that the unit tests
    #       don't start failing when environment variables change.
    pt_print(tokens, style=style, file=f, color_depth=ColorDepth.DEFAULT)
    assert b"\x1b[0;38;5;197mHello" in f.data
    assert b"\x1b[0;38;5;83;3mworld" in f.data 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:12,代码来源:test_print_formatted_text.py

示例13: _internal_prompt_print

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def _internal_prompt_print(self, *args, **kwargs):

        kwargs['sep'] = kwargs.pop('sep', ' ')
        kwargs['end'] = kwargs.pop('end', '\n')
        kwargs['file'] = kwargs.pop('file', sys.stdout)
        kwargs['style'] = token_style
        frags = []
        for a in args:
            if isinstance(a, FormattedText):
                frags.append(a)
            else:
                frags.append(FormattedText([("class:command", str(a))]))

        print_formatted_text(*frags, **kwargs) 
开发者ID:CityOfZion,项目名称:neo-python,代码行数:16,代码来源:PromptPrinter.py

示例14: printf

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def printf(self, mesg, addnl=True, color=None):
        if not self.colorsenabled:
            return self.outp.printf(mesg, addnl=addnl)

        # print_formatted_text can't handle \r
        mesg = mesg.replace('\r', '')

        if color is not None:
            mesg = FormattedText([(color, mesg)])
        return print_formatted_text(mesg, end='\n' if addnl else '') 
开发者ID:vertexproject,项目名称:synapse,代码行数:12,代码来源:cli.py

示例15: color_formatted_text

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import FormattedText [as 别名]
def color_formatted_text(data, msg_type):
    if msg_type in constants.STYLE:
        return FormattedText([('class:{}'.format(msg_type), data)])
    else:
        return FormattedText([('', data)]) 
开发者ID:nccgroup,项目名称:fuzzowski,代码行数:7,代码来源:helpers.py


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