Skip to content

Interactions

columbo provides five types of Interactions that can be used to control how the program will interact with the user:

  • Echo - Print text to the terminal, but don't stop to accept any input from the user.
  • Acknowledge - Print text to the terminal. Wait for the user to press Enter.
  • BasicQuestion - Print text to the terminal. Allow the user to type a text response. Pressing Enter submits the response.
  • Choice - Print text to the terminal, followed by a numbered list of options. Allow the user to enter the number of the option they wish to select. Pressing Enter submits the response.
  • Confirm - Print text to the terminal which expects a Yes or No answer. Pressing Y or N submits the corresponding response.

Creating Interactions

Echo & Acknowledge

Echo and Acknowledge both accept the following arguments.

  • message: The message to be displayed to the user.
  • should_ask: Optional. When given, the argument should be a function that accepts an Answers dictionary and returns True or False. Returning True indicates that the message should be displayed. Returning False will skip the message and not present it to the user. See Optional Questions & Branching for more details.

All Questions

BasicQuestion, Choice, & Confirm all accept the following arguments.

  • name: The identifier that will be used as the key to access this question's answer. Each question must have a unique value for name. Can't be dynamic.
  • message: The message to be displayed to the user.
  • default: The default answer to the question. This is used when the user does not provide an explicit value.
  • should_ask: Optional. When given, the argument should be a function that accepts an Answers dictionary and returns True or False. Returning True indicates that the question should be asked. Returning False will skip the question and not present it to the user. See Optional Questions & Branching for more details.
  • cli_help: Optional. A help message to be displayed for command line interface. See CLI documentation for more details. Can't be dynamic.
  • value_if_not_asked: Optional. A value used as an answer if the question is not asked. Can't be dynamic.

Basic Question

In addition to the arguments mentioned above, BasicQuestion also accepts the following argument.

  • validator: Optional. When given, the argument should be a function that checks if the user response is valid. Not providing this argument means that any value provided by the user will be accepted. See Validators for more details.

The default value for the BasicQuestion must satisfy the Validator. An exception will be raised if that is not the case.

Choice

In addition to the arguments mentioned above, Choice also accepts the following argument.

  • options: The set of possible values the user can choose from. This can be provided as a list of strings, or as a mapping of string to string where the key is what is recorded as the answer, and the value is what is displayed to the user.

Confirm

Confirm doesn't take any additional arguments that weren't mentioned above. However, the default argument takes a bool instead of str and defaults to False.