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


Python formatted_text.HTML属性代码示例

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


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

示例1: configure

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def configure(repl):
    # Probably, the best is to add a new PromptStyle to `all_prompt_styles` and
    # activate it. This way, the other styles are still selectable from the
    # menu.
    class CustomPrompt(PromptStyle):
        def in_prompt(self):
            return HTML("<ansigreen>Input[%s]</ansigreen>: ") % (
                repl.current_statement_index,
            )

        def in2_prompt(self, width):
            return "...: ".rjust(width)

        def out_prompt(self):
            return HTML("<ansired>Result[%s]</ansired>: ") % (
                repl.current_statement_index,
            )

    repl.all_prompt_styles["custom"] = CustomPrompt()
    repl.prompt_style = "custom" 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:22,代码来源:python-embed-with-custom-prompt.py

示例2: __init__

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def __init__(self, pymux, client_state):
        self.pymux = pymux
        self.client_state = client_state

        # Popup dialog for displaying keys, etc...
        search_textarea = SearchToolbar()
        self._popup_textarea = TextArea(scrollbar=True, read_only=True, search_field=search_textarea)
        self.popup_dialog = Dialog(
            title='Keys',
            body=HSplit([
                Window(FormattedTextControl(text=''), height=1),  # 1 line margin.
                self._popup_textarea,
                search_textarea,
                Window(
                    FormattedTextControl(
                        text=HTML('Press [<b>q</b>] to quit or [<b>/</b>] for searching.')),
                    align=WindowAlign.CENTER,
                    height=1)
                ])
            )

        self.layout = self._create_layout()

        # Keep track of render information.
        self.pane_write_positions = {} 
开发者ID:prompt-toolkit,项目名称:pymux,代码行数:27,代码来源:layout.py

示例3: main

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

示例4: main

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

示例5: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def main():
    custom_formatters = [
        formatters.Label(),
        formatters.Text(" "),
        formatters.SpinningWheel(),
        formatters.Text(" "),
        formatters.Text(HTML("<tildes>~~~</tildes>")),
        formatters.Bar(sym_a="#", sym_b="#", sym_c="."),
        formatters.Text(" left: "),
        formatters.TimeLeft(),
    ]
    with ProgressBar(
        title="Progress bar example with custom formatter.",
        formatters=custom_formatters,
        style=style,
    ) as pb:

        for i in pb(range(20), label="Downloading..."):
            time.sleep(1) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:21,代码来源:styled-2.py

示例6: prompt_continuation

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def prompt_continuation(width, line_number, wrap_count):
    """
    The continuation: display line numbers and '->' before soft wraps.

    Notice that we can return any kind of formatted text from here.

    The prompt continuation doesn't have to be the same width as the prompt
    which is displayed before the first line, but in this example we choose to
    align them. The `width` input that we receive here represents the width of
    the prompt.
    """
    if wrap_count > 0:
        return " " * (width - 3) + "-> "
    else:
        text = ("- %i - " % (line_number + 1)).rjust(width)
        return HTML("<strong>%s</strong>") % text 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:18,代码来源:get-multiline-input.py

示例7: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def main():
    # Option 1: pass a string to 'rprompt':
    answer = prompt("> ", rprompt=" <rprompt> ", style=example_style)
    print("You said: %s" % answer)

    # Option 2: pass HTML:
    answer = prompt("> ", rprompt=HTML(" <u>&lt;rprompt&gt;</u> "), style=example_style)
    print("You said: %s" % answer)

    # Option 3: pass ANSI:
    answer = prompt(
        "> ", rprompt=ANSI(" \x1b[4m<rprompt>\x1b[0m "), style=example_style
    )
    print("You said: %s" % answer)

    # Option 4: Pass a callable. (This callable can either return plain text,
    #           an HTML object, an ANSI object or a list of (style, text)
    #           tuples.
    answer = prompt("> ", rprompt=get_rprompt_text, style=example_style)
    print("You said: %s" % answer) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:22,代码来源:rprompt.py

示例8: _display_for_choice

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def _display_for_choice(choice: Text, index: int, word_before_cursor: Text) -> HTML:
        return HTML("{}<b><u>{}</u></b>{}").format(
            choice[:index],
            choice[index : index + len(word_before_cursor)],
            choice[index + len(word_before_cursor) : len(choice)],
        ) 
开发者ID:tmbo,项目名称:questionary,代码行数:8,代码来源:autocomplete.py

示例9: get_line_prefix

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def get_line_prefix(lineno, wrap_count):
    if wrap_count == 0:
        return HTML('[%s] <style bg="orange" fg="black">--&gt;</style> ') % lineno

    text = str(lineno) + "-" + "*" * (lineno // 2) + ": "
    return HTML('[%s.%s] <style bg="ansigreen" fg="ansiblack">%s</style>') % (
        lineno,
        wrap_count,
        text,
    )


# Global wrap lines flag. 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:15,代码来源:line-prefixes.py

示例10: title

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def title(text):
    print(HTML("\n<u><b>{}</b></u>").format(text)) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:4,代码来源:ansi.py

示例11: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def main():
    message_dialog(
        title=HTML(
            '<style bg="blue" fg="white">Styled</style> '
            '<style fg="ansired">dialog</style> window'
        ),
        text="Do you want to continue?\nPress ENTER to quit.",
        style=example_style,
    ).run() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:11,代码来源:styled_messagebox.py

示例12: interact

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def interact(connection):
    write = connection.send
    prompt_session = PromptSession()

    # When a client is connected, erase the screen from the client and say
    # Hello.
    clear()
    write("Welcome to our chat application!\n")
    write("All connected clients will receive what you say.\n")

    name = await prompt_session.prompt_async(message="Type your name: ")

    # Random color.
    color = random.choice(COLORS)
    _connection_to_color[connection] = color

    # Send 'connected' message.
    _send_to_everyone(connection, name, "(connected)", color)

    # Prompt.
    prompt_msg = HTML('<reverse fg="{}">[{}]</reverse> &gt; ').format(color, name)

    _connections.append(connection)
    try:
        # Set Application.
        while True:
            try:
                result = await prompt_session.prompt_async(message=prompt_msg)
                _send_to_everyone(connection, name, result, color)
            except KeyboardInterrupt:
                pass
    except EOFError:
        _send_to_everyone(connection, name, "(leaving)", color)
    finally:
        _connections.remove(connection) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:37,代码来源:chat-app.py

示例13: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def main():
    title = HTML('Downloading <style bg="yellow" fg="black">4 files...</style>')
    label = HTML("<ansired>some file</ansired>: ")

    with ProgressBar(title=title) as pb:
        for i in pb(range(800), label=label):
            time.sleep(0.01) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:9,代码来源:colored-title-and-label.py

示例14: example_2

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def example_2():
    """
    Using HTML for the formatting.
    """
    answer = prompt(
        HTML(
            "<username>john</username><at>@</at>"
            "<host>localhost</host>"
            "<colon>:</colon>"
            "<path>/user/john</path>"
            '<style bg="#00aa00" fg="#ffffff">#</style> '
        ),
        style=style,
    )
    print("You said: %s" % answer) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:17,代码来源:colored-prompt.py

示例15: test_html_with_style

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import HTML [as 别名]
def test_html_with_style():
    """
    Text `print_formatted_text` with `HTML` wrapped in `to_formatted_text`.
    """
    f = _Capture()

    html = HTML("<ansigreen>hello</ansigreen> <b>world</b>")
    formatted_text = to_formatted_text(html, style="class:myhtml")
    pt_print(formatted_text, file=f, color_depth=ColorDepth.DEFAULT)

    assert (
        f.data
        == b"\x1b[0m\x1b[?7h\x1b[0;32mhello\x1b[0m \x1b[0;1mworld\x1b[0m\r\n\x1b[0m"
    ) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:16,代码来源:test_print_formatted_text.py


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