(message: str, choices: list[Any])
| 95 | |
| 96 | |
| 97 | def prompt_select(message: str, choices: list[Any]) -> Any: |
| 98 | if is_notebook(): |
| 99 | print() |
| 100 | print(message) |
| 101 | real_choices = [] |
| 102 | |
| 103 | for i, choice in enumerate(choices, 1): |
| 104 | if isinstance(choice, Choice): |
| 105 | print(f"[{i}] {choice.title}") |
| 106 | real_choices.append(choice.value) |
| 107 | else: |
| 108 | print(f"[{i}] {choice}") |
| 109 | real_choices.append(choice) |
| 110 | |
| 111 | while True: |
| 112 | try: |
| 113 | selection = input("Enter number: ") |
| 114 | index = int(selection) - 1 |
| 115 | if 0 <= index < len(real_choices): |
| 116 | return real_choices[index] |
| 117 | print( |
| 118 | f"[red]Please enter a number between 1 and {len(real_choices)}[/]" |
| 119 | ) |
| 120 | except ValueError: |
| 121 | print("[red]Invalid input. Please enter a number.[/]") |
| 122 | else: |
| 123 | return questionary.select( |
| 124 | message, |
| 125 | choices=choices, |
| 126 | style=Style([("highlighted", "reverse")]), |
| 127 | ).ask() |
| 128 | |
| 129 | |
| 130 | def prompt_text( |
no test coverage detected