Console#
- class cli_interview_kit.Console[source]#
Bases:
Styled output and interactive prompts for a command.
Methods
print(renderable)Print a result to stdout: text, rich markup or a rich renderable.
info(message)Print an informational status line.
success(message)Print a success status line.
warning(message)Print a warning status line.
error(message)Print an error status line.
progress(description)Show a progress bar on stderr for a series of named steps.
select(prompt, choices, label)Ask for one of
choices.checkbox(prompt, choices, label[, checked])Ask for any number of
choices.confirm(prompt, default)Ask a yes/no question.
text(prompt[, default, validate, suggestions])Ask for free text, asking again until it is valid.
- print(renderable: object) None[source]#
Print a result to stdout: text, rich markup or a rich renderable.
- Parameters:
- renderableobject
Text, rich markup or any rich renderable.
- info(message: str) None[source]#
Print an informational status line.
- Parameters:
- messagestr
The text to show, printed literally.
- success(message: str) None[source]#
Print a success status line.
- Parameters:
- messagestr
The text to show, printed literally.
- warning(message: str) None[source]#
Print a warning status line.
- Parameters:
- messagestr
The text to show, printed literally.
- error(message: str) None[source]#
Print an error status line.
- Parameters:
- messagestr
The text to show, printed literally.
- progress(description: str) Generator[Callable[[int, int, str], None]][source]#
Show a progress bar on stderr for a series of named steps.
- Parameters:
- descriptionstr
What the steps do together, e.g.
"Checking files".
- Yields:
- Callable[[int, int, str], None]
update(index, total, detail): call it before each step, with the step’s 1-based index and what it is doing.
- select(prompt: str, choices: Sequence[T], label: Callable[[T], str]) T[source]#
Ask for one of
choices.- Parameters:
- promptstr
The question.
- choicesSequence[T]
What can be chosen.
- labelCallable[[T], str]
How each choice is shown.
- Returns:
- T
The chosen item.
- Raises:
- CliError
There is nothing to choose from.
- KeyboardInterrupt
The user cancels.
- checkbox(prompt: str, choices: Sequence[T], label: Callable[[T], str], checked: Sequence[T] | None = None) list[T][source]#
Ask for any number of
choices.- Parameters:
- promptstr
The question.
- choicesSequence[T]
What can be chosen.
- labelCallable[[T], str]
How each choice is shown.
- checkedSequence[T] | None
The choices ticked when the prompt opens; every choice when omitted, so the common answer “all of them” is one keypress.
- Returns:
- list[T]
The chosen items, in
choicesorder.
- Raises:
- CliError
There is nothing to choose from.
- KeyboardInterrupt
The user cancels.
- confirm(prompt: str, default: bool) bool[source]#
Ask a yes/no question.
- Parameters:
- promptstr
The question.
- defaultbool
The answer an empty reply gives.
- Returns:
- bool
The answer.
- Raises:
- KeyboardInterrupt
The user cancels.
- text(prompt: str, default: str = '', validate: Callable[[str], str] | None = None, suggestions: Sequence[str] = ()) str[source]#
Ask for free text, asking again until it is valid.
- Parameters:
- promptstr
The question.
- defaultstr
Text the input starts with.
- validateCallable[[str], str] | None
Raises
ValueErrorfor an invalid answer; its message is shown under the input until the answer changes.- suggestionsSequence[str]
Values listed under the input while they match what is typed. Any other value can still be entered.
- Returns:
- str
The answer.
- Raises:
- KeyboardInterrupt
The user cancels.