-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d475a3
commit 38043be
Showing
5 changed files
with
144 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Literal | ||
from simple_term_menu import TerminalMenu | ||
from rich import print | ||
from prompt_toolkit import prompt | ||
from prompt_toolkit.styles import Style | ||
|
||
|
||
def prompt_str(question: str, default: str) -> str: | ||
style = Style.from_dict( | ||
{ | ||
# User input (default text) | ||
"": "ansicyan", | ||
"mark": "ansicyan", | ||
"question": "ansiwhite", | ||
} | ||
) | ||
message = [ | ||
("class:mark", "? "), | ||
("class:question", f"{question.strip()} "), | ||
] | ||
return prompt(message, default="%s" % default, style=style) | ||
|
||
|
||
def prompt_options(question: str, options: list[str], default: str) -> str: | ||
terminal_menu = TerminalMenu( | ||
options, | ||
title=f"? {question}", | ||
menu_cursor="• ", | ||
menu_cursor_style=("bg_black", "fg_green"), | ||
menu_highlight_style=("bg_black", "fg_green"), | ||
) | ||
index = terminal_menu.show() | ||
answer = options[index] | ||
print(f"[cyan]?[/cyan] {question} [cyan]{answer}[/cyan]") | ||
return answer | ||
|
||
|
||
def prompt_bool(question: str, default: bool) -> bool: | ||
default_option = "Yes" if default == True else "No" | ||
answer = prompt_options(question, ["Yes", "No"], default_option) | ||
if answer == "Yes": | ||
return True | ||
elif answer == "No": | ||
return False | ||
else: | ||
raise Exception(f"unexpected input {answer}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters