plox.tools.interaction¶
Methods for user input/interaction/etc.
from plox.tools import interaction
Functions¶
|
Wrap an input string so that is is printed with blue coloring escape codes. |
|
Wrap an input string so that is is printed with bold red coloring escape codes. |
|
Get confirmation from a user regarding a message. |
|
Prompt the user with a menu and return a list of (potentially multiple) items they choose. |
|
Wrap an input string so that is is printed with red coloring escape codes. |
|
Prompt the user with a visual menu and return a single item they choose. |
|
Wrap an input string so that is is printed with yellow coloring escape codes. |
Module Contents¶
- plox.tools.interaction.blue(msg)¶
Wrap an input string so that is is printed with blue coloring escape codes.
- Return type:
- plox.tools.interaction.bold_red(msg)¶
Wrap an input string so that is is printed with bold red coloring escape codes.
- Return type:
- plox.tools.interaction.confirm(msg, yes_is_default=False, silent=False)¶
Get confirmation from a user regarding a message.
If
silent=True
is passed, validation from user input is skipped an method automatically continues.Example
>>> confirm("Proceed?") Proceed? (y/N) # entered "", default N False
>>> confirm("Proceed?") Proceed? (y/N) # entered "y" True
>>> confirm("Proceed?", yes_is_default=True) Proceed? (Y/n) # entered "", default Y True
>>> confirm("Proceed?", silent=True) True
- Parameters:
- Returns:
True
if user’s response is yes, elseFalse
.- Return type:
Prompt the user with a menu and return a list of (potentially multiple) items they choose.
- plox.tools.interaction.red(msg)¶
Wrap an input string so that is is printed with red coloring escape codes.
- Return type:
Prompt the user with a visual menu and return a single item they choose.
Example
>>> single_choice_menu(["foo", "bar", "baz"], "Pick one") # < spawns interactive terminal menu, selected foo > 'foo'
- Parameters:
prompt (str) – The prompt to display above the choices in the menu.
indicator (str) – Indicator icon on left hand side of current selection.
trim_suffix (Optional[str]) – Potential suffix to remove from the selected choice. Default is
None
. Useful in cases where menuing choices are ordered/sorted and say for example, the top pick is appened with... (latest)
but you’re still only interested in the...
- Return type: