Reference¶
prompts.prompt
¶
__all__ = ('Prompt')
module-attribute
¶
Prompt
¶
Low level prompt API.
answer: str = ''
instance-attribute
¶
answer_color = Fore.WHITE
instance-attribute
¶
output_file = output_file or sys.stdout
instance-attribute
¶
prompt_char = prompt_char
instance-attribute
¶
prompt_str = prompt_str
instance-attribute
¶
__enter__() -> Self
¶
__exit__(*_) -> None
¶
__init__(prompt_str: str, *, output_file: IO[str] | None = None, prompt_char: str = '?') -> None
¶
done() -> None
¶
error(error: str, *, color: str = Style.BRIGHT + Fore.RED) -> None
¶
finish() -> None
¶
render() -> str
¶
write(*messages: Any, nl: bool = False) -> None
¶
prompts.integration
¶
prompts.question
¶
Validator: TypeAlias = Callable[[str], ValidatorResult]
module-attribute
¶
ValidatorResult: TypeAlias = Union[str, bool]
module-attribute
¶
__all__ = ('ask', 'ValidatorResult', 'Validator')
module-attribute
¶
ask(question_str: str, *, default: str | None = None, initial: str | None = None, input_file: IO[str] | None = None, output_file: IO[str] | None = None, validate: Validator | list[Validator] | None = None, default_invalid: str = 'Invalid response.') -> str | None
¶
Ask a question with a prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
question_str |
str
|
Prompt to show the user. |
required |
initial |
str | None
|
Initial value, as shown in |
None
|
input_file |
IO[str] | None
|
File descriptor to read input from. |
None
|
output_file |
IO[str] | None
|
File descriptor to write output to. |
None
|
validate |
Validator | list[Validator] | None
|
Validator(s) to be used for validation of the input. |
None
|
default_invalid |
str
|
Default message to show the user if a validator returns |
'Invalid response.'
|
Raises:
Type | Description |
---|---|
KeyboardInterrupt
|
User pressed CTRL+C |
Returns:
Type | Description |
---|---|
str | None
|
The inputted value. |
prompts.radio(items: Sequence[str], *, multi_line: bool = False, input_file: IO[str] | None = None, output_file: IO[str] | None = None, selected_color: str = Fore.GREEN + Style.DIM + UNDERLINE, transient: bool = False) -> int
¶
Display a radio selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
Sequence[str]
|
Sequence of available selections. Must have at least 2 values. |
required |
input_file |
IO[str] | None
|
File descriptor to read input from. |
None
|
output_file |
IO[str] | None
|
File descriptor to write output to. |
None
|
selected_color |
str
|
Color to use for selected values. Green by default. |
GREEN + DIM + UNDERLINE
|
transient |
bool
|
Whether to delete the radio selection after it's done. |
False
|
Raises:
Type | Description |
---|---|
KeyboardInterrupt
|
User pressed CTRL+C |
Returns:
Type | Description |
---|---|
int
|
Index of the selected item. |
prompts.input
¶
__all__ = ('take_input')
module-attribute
¶
take_input(file: IO[str] | None = None, *, output: IO[str] | None = None, autocomplete: Sequence[str] | None = None, min_autocomplete_chars: int = 2, initial: str | None = None, initial_color: str = Fore.BLACK + Style.BRIGHT + ITALIC, color_sequence: str = Fore.WHITE) -> str
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
IO[str] | None
|
File to read from. |
None
|
output |
IO[str] | None
|
Output file to print to. |
None
|
autocomplete |
Sequence[str] | None
|
List of strings available for autocomplete. |
None
|
min_autocomplete_chars |
int
|
Minimum amount of characters to be entered before autocomplete shows up. |
2
|
initial |
str | None
|
Initial value to show before a value is inputted. |
None
|
initial_color |
str
|
Color of the initial value. Gray by default. |
BLACK + BRIGHT + ITALIC
|
color_sequence |
str
|
Color of the inputted characters. White by default. |
WHITE
|
Returns:
Type | Description |
---|---|
str
|
The inputted string. |
Raises:
Type | Description |
---|---|
KeyboardInterrupt
|
User pressed CTRL+C |