Prompt API Reference¶
Auto-generated API documentation for the prompt module.
prompt
¶
Zero-dependency interactive CLI prompts (confirm, select, text).
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
Provides interactive command-line prompts similar to questionary,
using only the Python standard library. Works on Linux, macOS (via
termios/tty) and Windows (via msvcrt) with an automatic
fallback to plain input() when a TTY is unavailable.
Basic usage::
answer = confirm("Continue?")
choice = select("Pick one:", ["a", "b", "c"])
name = text("Your name:", validate=lambda s: True if s else "Required")
Style
¶
ANSI styling configuration for prompts.
Users may supply a list of (role, style_string) tuples to customise
how each visual element is rendered. Recognised roles are "question",
"answer", "pointer", "highlighted", "error", and
"instruction".
Example::
style = Style([
("question", "fg:#00ff00 bold"),
("answer", "fg:#ffffff"),
])
confirm("Continue?", style=style)
Source code in prompt/prompt.py
apply(role, text)
¶
Wrap text with the ANSI codes for role and a trailing reset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
str
|
One of the recognised role names. |
required |
text
|
str
|
The text to style. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The styled string with a trailing ANSI reset sequence, |
str
|
or plain text when colors are disabled. |
Source code in prompt/prompt.py
confirm(message, default=True, style=None, *, input_stream=None, output_stream=None)
¶
Ask a yes/no question.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The question to display. |
required |
default
|
bool
|
Pre-selected answer ( |
True
|
style
|
Style | None
|
Optional |
None
|
input_stream
|
TextIO | None
|
Override for |
None
|
output_stream
|
TextIO | None
|
Override for |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
|
bool | None
|
cancelled with Ctrl-C. |
Example::
if confirm("Proceed with installation?"):
install()
Source code in prompt/prompt.py
select(message, choices, default=None, style=None, *, input_stream=None, output_stream=None)
¶
Show a list of choices with arrow-key navigation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The question to display above the list. |
required |
choices
|
list[str] | list[dict[str, str]]
|
Either plain strings or |
required |
default
|
str | None
|
Value to pre-select. Defaults to the first choice. |
None
|
style
|
Style | None
|
Optional |
None
|
input_stream
|
TextIO | None
|
Override for |
None
|
output_stream
|
TextIO | None
|
Override for |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The |
Example::
lang = select("Language:", ["Python", "Rust", "Go"])
Source code in prompt/prompt.py
text(message, default='', validate=None, style=None, *, input_stream=None, output_stream=None)
¶
Prompt the user for free-form text input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The question to display. |
required |
default
|
str
|
Default value (used when the user presses Enter without typing anything). |
''
|
validate
|
Callable[[str], bool | str] | None
|
Optional callable that receives the current input string.
Return |
None
|
style
|
Style | None
|
Optional |
None
|
input_stream
|
TextIO | None
|
Override for |
None
|
output_stream
|
TextIO | None
|
Override for |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The entered string, or |
Example::
name = text("Your name:", validate=lambda s: True if s else "Name required")