plox.tools.interaction

Methods for user input/interaction/etc.

from plox.tools import interaction

Functions

blue(msg)

Wrap an input string so that is is printed with blue coloring escape codes.

bold_red(msg)

Wrap an input string so that is is printed with bold red coloring escape codes.

confirm(msg[, yes_is_default, silent])

Get confirmation from a user regarding a message.

multi_choice_menu(choices, prompt[, indicator])

Prompt the user with a menu and return a list of (potentially multiple) items they choose.

red(msg)

Wrap an input string so that is is printed with red coloring escape codes.

single_choice_menu(choices, prompt[, indicator, ...])

Prompt the user with a visual menu and return a single item they choose.

yellow(msg)

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:

str

plox.tools.interaction.bold_red(msg)

Wrap an input string so that is is printed with bold red coloring escape codes.

Return type:

str

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:
  • msg (str) – The prompt to get Y/N input from the user on.

  • yes_is_default (bool) – Optional, if provided, the default (empty enter behaviour will be Y)

  • silent (bool) – Whether or not to skip user input and just return true immediately.

Returns:

True if user’s response is yes, else False.

Return type:

bool

plox.tools.interaction.multi_choice_menu(choices, prompt, indicator='=>')

Prompt the user with a menu and return a list of (potentially multiple) items they choose.

Parameters:
  • choices (list[str]) – The list of options to choose from.

  • prompt (str) – The prompt to display above the choices in the menu.

  • indicator (str) – Indicator icon on left hand side of current selection.

Return type:

list[str]

plox.tools.interaction.red(msg)

Wrap an input string so that is is printed with red coloring escape codes.

Return type:

str

plox.tools.interaction.single_choice_menu(choices, prompt, indicator='=>', trim_suffix=None)

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:
  • choices (list[str]) – The list of options to choose from.

  • 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:

str

plox.tools.interaction.yellow(msg)

Wrap an input string so that is is printed with yellow coloring escape codes.

Return type:

str