yera.console.prompts

Reusable Rich Prompt subclasses and prompt helper functions for terminal input.

Symbols

class ButtonsPrompt — Prompt that shows a numbered list and returns the selected option string.
class DatePrompt — Prompt that validates YYYY-MM-DD and returns the date string.
def prompt_buttons — Show numbered options and prompt for a choice (1-n). Returns the selected option string.
def prompt_date — Prompt for a date (YYYY-MM-DD), re-prompt until valid. Returns ISO date string.
def prompt_slider — Show slider prompt (label, range, default) and return validated float in range.
def prompt_text — Prompt for a single line of text. Returns the string entered.
class SliderPrompt — FloatPrompt that enforces min/max range. Raise InvalidResponse if out of range.

ButtonsPrompt

Inherits: Prompt

Prompt that shows a numbered list and returns the selected option string.

Methods

pre_prompt — Display label and numbered list before the prompt.
process_response — Parse choice number and return the selected option string.

ButtonsPrompt.pre_prompt

pre_prompt() → None

Display label and numbered list before the prompt.

ButtonsPrompt.process_response

process_response(
    value: str,
) → str

Parse choice number and return the selected option string.

DatePrompt

Inherits: Prompt

Prompt that validates YYYY-MM-DD and returns the date string.

Methods

process_response — Validate ISO date and return the string.

DatePrompt.process_response

process_response(
    value: str,
) → str

Validate ISO date and return the string.

prompt_buttons

prompt_buttons(
    console: Console,
    options: list[str],
    label: str | None = None,
) → str

Show numbered options and prompt for a choice (1-n). Returns the selected option string.

prompt_date

prompt_date(
    console: Console,
    label: str,
    default_date: date,
) → str

Prompt for a date (YYYY-MM-DD), re-prompt until valid. Returns ISO date string.

prompt_slider

prompt_slider(
    console: Console,
    label: str,
    min_value: float,
    max_value: float,
    default: float,
) → float

Show slider prompt (label, range, default) and return validated float in range.

prompt_text

prompt_text(
    console: Console,
    message: str,
) → str

Prompt for a single line of text. Returns the string entered.

SliderPrompt

Inherits: FloatPrompt

FloatPrompt that enforces min/max range. Raise InvalidResponse if out of range.

Methods

process_response — Parse float and validate it is within min/max range.
ask_range — Ask for a float within the given range. Builds prompt from label and range.

SliderPrompt.process_response

process_response(
    value: str,
) → float

Parse float and validate it is within min/max range.

SliderPrompt.ask_range

ask_range(
    label: str,
    min_value: float,
    max_value: float,
    default: float,
    console: Console | None = None,
) → float

Ask for a float within the given range. Builds prompt from label and range.