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