Python rich 库 - Pretty Printing
Prompt
Rich 有许多 Prompt 类,它们用于要求用户输入信息并循环,直到收到有效的响应(它们都在内部使用 Console API)
|
|
The prompt may be given as a string (which may contain Console Markup and emoji code) or as a Text
instance.
You can set a default value which will be returned if the user presses return without entering any text:
|
|
If you supply a list of choices, the prompt will loop until the user enters one of the choices:
|
|
In addition to Prompt
which returns strings, you can also use IntPrompt
which asks the user for an integer, and FloatPrompt
for floats.
The Confirm
class is a specialized prompt which may be used to ask the user a simple yes / no question. Here’s an example:
|
|
The Prompt class was designed to be customizable via inheritance. See prompt.py for examples.
To see some of the prompts in action, run the following command from the command line:
|
|