yera.runtime.handlers.form._prompts
Ask for form fields one at a time in text-based environments.
Symbols
collect_form_values
collect_form_values(
data: FormData,
prompter: FormPrompter,
) → dict[str, JsonValue]Ask for a form's fields and return the answers as a JSON object.
On a re-presented form, only fields with errors and fields holding secrets are asked again; every other value is kept as submitted.
Parameters
The form request, including any values and errors to re-present.
Asks each question in the current environment.
Returns
The answers keyed by field name, ready to submit as form input.
FormPrompter
ProtocolAsks single questions in a text-based environment.
Methods
FormPrompter.heading
heading(
text: str,
) → NoneIntroduce a group of related questions.
Parameters
Plain-text heading to present.
FormPrompter.error
error(
text: str,
) → NoneReport a problem found in a rejected submission.
Parameters
Plain-text validation message to present.
FormPrompter.text
text(
message: str,
default: str,
validate: Validator | None = None,
) → strAsk for free text, repeating while validation fails.
Parameters
Plain-text prompt shown to the user.
Value used when the user submits an empty response.
Optional callback returning a validation message for an
unacceptable answer, or None when the answer is valid.
Returns
The accepted text response.
FormPrompter.secret
secret(
message: str,
) → strAsk for text without displaying the entered value.
Parameters
Plain-text prompt shown to the user.
Returns
The entered secret value.
FormPrompter.confirm
confirm(
message: str,
default: bool,
) → boolAsk a yes-or-no question.
Parameters
Plain-text question shown to the user.
Answer used when the user accepts the default.
Returns
Whether the user answered yes.
FormPrompter.select
select(
message: str,
choices: list[str],
default: str | None,
) → strAsk the user to choose one value.
Parameters
Plain-text prompt shown to the user.
Labels available for selection.
Choice selected by default, or None for no default.
Returns
The selected choice label.
FormPrompter.checkbox
checkbox(
message: str,
choices: list[str],
selected: list[str],
) → list[str]Ask the user to choose any number of values.
Parameters
Plain-text prompt shown to the user.
Labels available for selection.
Choices selected by default.
Returns
The selected choice labels in their presentation order.