PromptUtils¶
Utility class with various routines for prompting for user input.
Creates a new instance of ConsoleUtils with the specified console. If no console was specified, creates a new default console using the ConsoleFactory.
Parameters: - screen (
consolemenu.screen.Screen
) – The Screen instance. - prompt_formatter (
PromptFormatter
, optional) – The instance of PromptFormatter for displaying the prompt.
Clear the screen.
Prompts the user to confirm a question with a yes/no prompt. If no message is specified, the default message is: “You entered {}. Is this correct?”
Parameters: - answer (str) – The answer to confirm.
- message (str, optional) – Optional message if a different confirmation prompt is desired.
Returns: True if the user confirmed Yes, or False if user specified No.
Return type: bool
A console prompt to ask the user to ‘Press [Enter] to continue’.
Parameters: message (str, optional) – A message to display in place of the default.
Generic prompt the user for input.
Parameters: - prompt (str) – The message to prompt the user.
- default (str, optional) – The default value to suggest as an answer.
- validators (
BaseValidator
, optional) – The list of validators to perform input validation. - enable_quit (bool, optional) – Specifies whether the user can cancel out of the input prompt.
- quit_string (str, optional) – The string which the user must input in order to quit.
- quit_message (str, optional) – The message to explain how to quit.
Returns: an InputResult tuple.
Return type: InputResult
Prompt the user for a password or other confidential data.
This is equivalent to the input() method, but does not echo inputted characters to the screen.
Parameters: message (str) – The prompt message. Returns: The password provided by the user. Return type: str
Prints the specified arguments to the screen.
Parameters: *args – Variable length argument list.
Prints the specified arguments to the screen, followed by a newline character.
Parameters: *args – Variable length argument list.
Prompt for a password using the given message, then prompt a second time for a confirmation password, and verify both provided passwords match. If the passwords do not match, an error is displayed, “Passwords do not match”, and the user must input both passwords again.
Parameters: message (str) – The prompt message. Returns: The password. Return type: str
Prompt the user for a response that must be one of the two supplied choices.
NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options.
Parameters: - prompt (str) – The prompt to present the choices to the user.
- option1 (str) – The first option.
- option2 (str) – The second option.
Returns: The choice selected by the user.
Return type: str
Displays a numbered vertical list of choices from the provided list of strings.
Parameters: - choices (
list
ofstr
) – The list of choices to display. - title (str, optional) – Optional title to display above the numbered list.
- prompt (str) – The prompt string. Default is “>”.
Returns: The index of selected choice.
Return type: int
- choices (
Prompt the user for a response that must be one of the three supplied choices.
NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options.
Parameters: - prompt (str) – The prompt to present the choices to the user.
- option1 (str) – The first option.
- option2 (str) – The second option.
- option3 (str) – The third option.
Returns: The choice selected by the user.
Return type: str
Prompts the user with the specified question, and expects a yes (y) or no (n) response, returning a boolean value representing the user’s answer.
Parameters: prompt (str) – The prompt to display to the user. Returns: True for yes, False for no. Return type: bool
The Screen instance.
Type: consolemenu.screen.Screen
Validate the given input string against the specified list of validators.
Parameters: - input_string (str) – The input string to verify.
- validators (
list
ofBaseValidator
) – The list of validators.
Returns: The validation result. True if the input is valid; False otherwise.
Return type: bool
Raises: InvalidValidator – If the list of validators contains an invalid BaseValidator class.
- screen (