File: frame-and-bottom-toolbar.py

package info (click to toggle)
prompt-toolkit 3.0.52-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,628 kB
  • sloc: python: 31,599; makefile: 151; sh: 6
file content (40 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

from prompt_toolkit.filters import is_done
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.shortcuts import choice
from prompt_toolkit.styles import Style


def main() -> None:
    style = Style.from_dict(
        {
            "frame.border": "#ff4444",
            "selected-option": "bold",
            # We use 'noreverse' because the default style for 'bottom-toolbar'
            # uses 'reverse'.
            "bottom-toolbar": "#ffffff bg:#333333 noreverse",
        }
    )

    result = choice(
        message=HTML("<u>Please select a dish</u>:"),
        options=[
            ("pizza", "Pizza with mushrooms"),
            ("salad", "Salad with tomatoes"),
            ("sushi", "Sushi"),
        ],
        style=style,
        bottom_toolbar=HTML(
            " Press <b>[Up]</b>/<b>[Down]</b> to select, <b>[Enter]</b> to accept."
        ),
        # Use `~is_done`, if you only want to show the frame while editing and
        # hide it when the input is accepted.
        # Use `True`, if you always want to show the frame.
        show_frame=~is_done,
    )
    print(result)


if __name__ == "__main__":
    main()