MCPcopy
hub / github.com/p-e-w/heretic / prompt_select

Function prompt_select

src/heretic/utils.py:97–127  ·  view source on GitHub ↗
(message: str, choices: list[Any])

Source from the content-addressed store, hash-verified

95
96
97def 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
130def prompt_text(

Callers 3

obtain_export_strategyFunction · 0.85
runFunction · 0.85
check_environmentFunction · 0.85

Calls 1

is_notebookFunction · 0.85

Tested by

no test coverage detected