Skip to content

Commit 3f65292

Browse files
docs
1 parent 70f9d66 commit 3f65292

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

docs/images/choice-input.png

57.9 KB
Loading

docs/images/choice-with-frame.png

68.4 KB
Loading

docs/images/colored-choice.png

62.3 KB
Loading

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Table of contents
6969
pages/upgrading/index
7070
pages/printing_text
7171
pages/asking_for_input
72-
pages/choice_prompts
72+
pages/asking_for_a_choice
7373
pages/dialogs
7474
pages/progress_bars
7575
pages/full_screen_apps

docs/pages/choice_prompts.rst renamed to docs/pages/asking_for_a_choice.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ from a list of options:
1313
from prompt_toolkit.shortcuts import choice
1414
1515
result = choice(
16-
message="Please choose a dish",
16+
message="Please choose a dish:",
1717
options=[
1818
("pizza", "Pizza with mushrooms"),
1919
("salad", "Salad with tomatoes"),
2020
("sushi", "Sushi"),
2121
],
2222
default="salad",
2323
)
24+
print(f"You have chosen: {result}")
2425
25-
print(f"You have chosen: {text}")
26+
.. image:: ../images/choice-input.png
2627

2728

2829
Coloring the options
2930
--------------------
3031

31-
Similar to text input prompts, it is possible to customize the colors and
32-
styles. The ``message`` parameter takes any :ref:`formatted text
33-
<formatted_text>`, and the labels (2nd argument of the options) can also be
34-
:ref:`formatted text <formatted_text>`. Further, we can pass a
35-
:class:`~prompt_toolkit.styles.Style` instance using the
32+
It is possible to customize the colors and styles. The ``message`` parameter
33+
takes any :ref:`formatted text <formatted_text>`, and the labels (2nd argument
34+
from the options) can be :ref:`formatted text <formatted_text>` as well.
35+
Further, we can pass a :class:`~prompt_toolkit.styles.Style` instance using the
3636
:meth:`~prompt_toolkit.styles.Style.from_dict` function:
3737

3838
.. code:: python
@@ -48,7 +48,6 @@ styles. The ``message`` parameter takes any :ref:`formatted text
4848
"input-selection": "fg:#ff0000",
4949
"number": "fg:#884444 bold",
5050
"selected-option": "underline",
51-
"frame.border": "#884444",
5251
}
5352
)
5453
@@ -66,15 +65,17 @@ styles. The ``message`` parameter takes any :ref:`formatted text
6665
)
6766
print(result)
6867
68+
.. image:: ../images/colored-choice.png
69+
6970

7071
Adding a frame
7172
--------------
7273

7374
The :func:`~prompt_toolkit.shortcuts.choice` function takes a
74-
``show_frame`` argument. When set to ``True``, the options will be shown
75-
inside a frame. It is also possible to pass a :ref:`filter <filters>`, like
76-
``~is_done``, so that the frame is only displayed when asking for input, but
77-
hidden once the input is accepted.
75+
``show_frame`` argument. When ``True``, the input is displayed within a frame.
76+
It is also possible to pass a :ref:`filter <filters>`, like ``~is_done``, so
77+
that the frame is only displayed when asking for input, but hidden once the
78+
input is accepted.
7879

7980
.. code:: python
8081
@@ -85,7 +86,7 @@ hidden once the input is accepted.
8586
style = Style.from_dict(
8687
{
8788
"frame.border": "#884444",
88-
"selected-option": "bold underline",
89+
"selected-option": "bold",
8990
}
9091
)
9192
result = choice(
@@ -100,4 +101,4 @@ hidden once the input is accepted.
100101
)
101102
print(result)
102103
103-
104+
.. image:: ../images/choice-with-frame.png

docs/pages/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Shortcuts
9696
:members: prompt, PromptSession, confirm, CompleteStyle,
9797
create_confirm_session, clear, clear_title, print_formatted_text,
9898
set_title, ProgressBar, input_dialog, message_dialog, progress_dialog,
99-
radiolist_dialog, yes_no_dialog, button_dialog, select_input
99+
radiolist_dialog, yes_no_dialog, button_dialog, choice
100100

101101
.. automodule:: prompt_toolkit.shortcuts.progress_bar.formatters
102102
:members:

0 commit comments

Comments
 (0)