-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Windows and MacOS * Add questionary dependency * Remove the tests * Remove print
- Loading branch information
Showing
8 changed files
with
489 additions
and
432 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
import re | ||
from typing import Tuple, TypeVar | ||
from typing import TypeVar | ||
|
||
from bullet import Bullet, SlidePrompt, colors | ||
from bullet.client import YesNo | ||
import questionary | ||
|
||
EnumType = TypeVar("EnumType") | ||
|
||
WHITE_FOREGROUND = colors.foreground["white"] | ||
|
||
|
||
def camel_to_snake(text: str) -> str: | ||
return re.sub(r"(?<!^)(?=[A-Z])", "_", text).lower() | ||
|
||
|
||
def bullet(choices: EnumType) -> Bullet: | ||
def question(choices: EnumType) -> questionary.Question: | ||
prompt = camel_to_snake(choices.__name__).replace("_", " ") # type: ignore | ||
return Bullet( | ||
prompt=f"Select the {prompt}: ", | ||
choices=list(choices), # type: ignore | ||
bullet=" >", | ||
margin=2, | ||
word_color=WHITE_FOREGROUND, | ||
word_on_switch=WHITE_FOREGROUND, | ||
) | ||
|
||
|
||
def yes_no(option: str) -> YesNo: | ||
return YesNo( | ||
prompt=f"Do you want {option}?", default="n", word_color=WHITE_FOREGROUND | ||
) | ||
|
||
|
||
def launch_cli(*prompt_objs: Tuple[str, Bullet]): | ||
names, objs = zip(*prompt_objs) | ||
results = SlidePrompt(objs).launch() | ||
return {name: result[1] for name, result in zip(names, results)} | ||
return questionary.select(f"Select the {prompt}: ", choices=list(choices)) | ||
|
||
|
||
def binary_question(option: str) -> questionary.Question: | ||
return questionary.confirm(f"Do you want {option}?", default=False) |
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
Oops, something went wrong.