2024-02-02 13:49:39 +00:00
|
|
|
from concurrent.futures import Future
|
|
|
|
|
2024-01-30 00:32:04 +00:00
|
|
|
import click
|
|
|
|
|
|
|
|
|
2024-02-02 13:49:39 +00:00
|
|
|
def click_prompt(options: dict[int, str], text: str, default: int) -> Future[int | None]:
|
2024-01-30 00:32:04 +00:00
|
|
|
for idx, label in options.items():
|
|
|
|
if label:
|
|
|
|
click.echo(f"{idx}: {label}")
|
2024-02-02 13:49:39 +00:00
|
|
|
user_choice = click.prompt(text=text, default=default)
|
|
|
|
user_choice = int(user_choice)
|
|
|
|
ret = Future()
|
|
|
|
if user_choice not in options:
|
2024-01-30 00:32:04 +00:00
|
|
|
click.echo("Invalid choice.")
|
2024-02-02 13:49:39 +00:00
|
|
|
ret.set_result(None)
|
|
|
|
else:
|
|
|
|
ret.set_result(user_choice)
|
2024-01-30 00:32:04 +00:00
|
|
|
return ret
|