Skip to content

ui.questionary_ui_helper

QuestionaryUIHelper

QuestionaryUIHelper(style: Optional[Style] = None)

Bases: _UiHelperBase

UI helper implementation using Questionary for interactive prompts.

Initializes the QuestionaryUIHelper with an optional custom style.

Source code in src/clabe/ui/questionary_ui_helper.py
78
79
80
def __init__(self, style: Optional[questionary.Style] = None) -> None:
    """Initializes the QuestionaryUIHelper with an optional custom style."""
    self.style = style or custom_style

print

print(message: str) -> None

Prints a message with custom styling.

Source code in src/clabe/ui/questionary_ui_helper.py
82
83
84
def print(self, message: str) -> None:
    """Prints a message with custom styling."""
    questionary.print(message, "bold italic")

input

input(prompt: str) -> str

Prompts the user for input with custom styling.

Source code in src/clabe/ui/questionary_ui_helper.py
86
87
88
89
def input(self, prompt: str) -> str:
    """Prompts the user for input with custom styling."""
    _flush_input()
    return _ask_sync(questionary.text(prompt, style=self.style)) or ""

prompt_pick_from_list

prompt_pick_from_list(
    value: List[str], prompt: str, **kwargs
) -> Optional[str]

Interactive list selection with visual highlighting using arrow keys or number shortcuts.

Source code in src/clabe/ui/questionary_ui_helper.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def prompt_pick_from_list(self, value: List[str], prompt: str, **kwargs) -> Optional[str]:
    """Interactive list selection with visual highlighting using arrow keys or number shortcuts."""
    _flush_input()
    allow_0_as_none = kwargs.get("allow_0_as_none", True)
    zero_label = kwargs.get("zero_label", "None")

    choices = []

    if allow_0_as_none:
        choices.append(zero_label)

    choices.extend(value)

    result = _ask_sync(
        questionary.select(
            prompt,
            choices=choices,
            style=self.style,
            use_arrow_keys=True,
            use_indicator=True,
            use_shortcuts=True,
        )
    )

    if result is None:
        return None

    if result == zero_label and allow_0_as_none:
        return None

    return result

prompt_yes_no_question

prompt_yes_no_question(prompt: str) -> bool

Prompts the user with a yes/no question using custom styling.

Source code in src/clabe/ui/questionary_ui_helper.py
123
124
125
126
def prompt_yes_no_question(self, prompt: str) -> bool:
    """Prompts the user with a yes/no question using custom styling."""
    _flush_input()
    return _ask_sync(questionary.confirm(prompt, style=self.style)) or False

prompt_text

prompt_text(prompt: str) -> str

Prompts the user for generic text input using custom styling.

Source code in src/clabe/ui/questionary_ui_helper.py
128
129
130
131
def prompt_text(self, prompt: str) -> str:
    """Prompts the user for generic text input using custom styling."""
    _flush_input()
    return _ask_sync(questionary.text(prompt, style=self.style)) or ""

prompt_float

prompt_float(prompt: str) -> float

Prompts the user for a float input using custom styling.

Source code in src/clabe/ui/questionary_ui_helper.py
133
134
135
136
137
138
139
140
141
142
def prompt_float(self, prompt: str) -> float:
    """Prompts the user for a float input using custom styling."""
    _flush_input()
    while True:
        try:
            value_str = _ask_sync(questionary.text(prompt, style=self.style))
            if value_str:
                return float(value_str)
        except ValueError:
            self.print("Invalid input. Please enter a valid float.")