Used to communicate between the application and the user. The Prompt class can be subclassed to provide custom implementations of read and write to alter the input/output sources. By default, stdin and stdout will be used.
Creates a new instance that will read and write to the given streams.
Parameters: |
|
---|
Centers the given text. Nothing is output to the screen; the formatted string is returned. The width in which to center is the first non-None value in the following order:
- Provided width parameter
- Instance-level wrap_width value
- Terminal width
Parameters: |
|
---|---|
Returns: | string with spaces padding the left to center it |
Return type: | str |
Writes one of the clear characters to the screen. If none is given, the entire screen is cleared. One of the CLEAR_* variables can be used to scope the cleared space.
Parameters: | clear_character (str) – character code to write; should be one of the CLEAR_* variables |
---|
Colors the given text with the given color, resetting the output back to whatever color is defined in this instance’s normal_color. Nothing is output to the screen; the formatted string is returned.
Parameters: |
|
---|---|
Returns: | new string with the proper color escape sequences in place |
Return type: | str |
Returns the values for all tags that were passed to read calls. If record_tags is enabled on this instance and a tag was not specified, an empty string will be added in its place.
Returns: | list of tag values; empty list if record_tags was set to false |
---|---|
Return type: | list |
Returns all tags for both read and write calls. Unlike read_tags and write_tags, the return value is a list of tuples. The first entry in the tuple will be one of [TAG_READ, TAG_WRITE] to indicate what triggered the tag. The second value in the tuple is the tag itself.
Returns: | list of tag tuples: (tag_type, tag_value); empty list if record_tags was set to false |
---|---|
Return type: | list |
Returns the values for all tags that were passed to write calls. If record_tags is enabled on this instance and a tag was not specified, an empty string will be added in its place.
Returns: | list of tag values; empty list if record_tags was set to false |
---|---|
Return type: | list |
Writes the given move cursor character to the screen without a new line character. Values for direction should be one of the MOVE_* variables.
Parameters: | direction (str) – move character to write |
---|
Prompts the user for an answer to the given question, re-prompting if the answer is blank.
Parameters: |
|
---|---|
Returns: | answer to the given question or the ABORT constant in this module if it was interrupted |
Prompts the user for an answer to the given question. If the user does not enter a value, the default will be returned.
Parameters: | default_value (string) – if the user does not enter a value, this value is returned |
---|
Prompts the user for the full path to a file, reprompting if the file does not exist. If allow_empty is specified, the validation will only be performed if the user enters a value.
Displays a list of items, allowing the user to select a single item in the list. The index of the selected item is returned. If interruptable is set to true and the user exits (through ctrl+c), the ABORT constant is returned.
Parameters: |
|
---|---|
Returns: | index of the selected item; ABORT if the user elected to abort |
Return type: | int or ABORT |
Displays a list of items, allowing the user to select 1 or more items before continuing. The items selected by the user are returned.
Returns: | list of indices of the items the user selected, empty list if none are selected; ABORT is returned if the user selects to abort the menu |
---|---|
Return type: | list or ABORT |
Displays a multiselect menu for the user where the items are broken up by section, however the numbering is consecutive to provide unique indices for the user to use for selection. Entries from one or more section may be toggled; the section headers are merely used for display purposes.
Each key in section_items is displayed as the section header. Each item in the list at that key will be rendered as belonging to that section.
The returned value will be a dict that maps each section header (i.e. key in section_items) and the value is a list of indices that were selected from the original list passed in section_items under that key. If no items were selected under a given section, an empty list is the value in the return for each section key.
For example, given the input data:
{ 'Section 1' : ['Item 1.1', 'Item 1.2'],
'Section 2' : ['Item 2.1'],}
The following is rendered for the user:
Section 1
- 1 : Item 1.1
- 2 : Item 1.2
Section 2
- 3 : Item 2.1
If the user entered 1, 2, and 3, thus toggling them as selected, the following would be returned:
{ 'Section 1' : [0, 1],
'Section 2' : [0],}
However, if only 2 was toggled, the return would be:
{ 'Section 1' : [1],
'Section 2' : [],}
If the user chooses the “abort” option, None is returned.
Parameters: |
|
---|---|
Returns: | selected indices for each list specified in each section; ABORT if the user elected to abort the selection |
Return type: | dict {str : list[int]} or ABORT |
Prompts the user for a numerical input. If the given value does not represent a number, the user will be re-prompted until a valid number is provided.
Returns: | number entered by the user that conforms to the parameters in this call |
---|---|
Return type: | int |
Prompts the user for a password. If a verify question is specified, the user will be prompted to match the previously entered password (suitable for things such as changing a password). If it is not specified, the first value entered will be returned.
The user entered text will not be echoed to the screen.
Returns: | entered password |
---|---|
Return type: | str |
Prompts the user to enter a number between the given range. If the input is invalid, the user wil be re-prompted until a valid number is provided.
Prompts the user for the answer to a question where only an enumerated set of values should be accepted.
Parameters: | values (list) – list of acceptable answers to the question |
---|---|
Returns: | will be one of the entries in the values parameter |
Return type: | string |
Prompts the user for the answer to a yes/no question, assuming the value ‘y’ for yes and ‘n’ for no. If neither is entered, the user will be re-prompted until one of the two is indicated.
Returns: | True if ‘y’ was specified, False otherwise |
---|---|
Return type: | boolean |
Reads user input. This will likely not be called in favor of one of the prompt_* methods.
Parameters: | prompt (string) – the prompt displayed to the user when the input is requested |
---|---|
Returns: | the input specified by the user |
Return type: | string |
Moves the cursor back to the location of the cursor at the last point save_position was called.
Saves the current location of the cursor. The cursor can be moved back to this position by using the reset_position call.
Returns the width and height of the terminal.
Returns: | tuple of width and height values |
---|---|
Return type: | (int, int) |
If the wrap_width is specified, this call will introduce new line characters to maintain that width.
Parameters: |
|
---|---|
Returns: | wrapped version of the content string |
Return type: | str |
Writes content to the prompt’s output stream.
Parameters: |
|
---|