def prompt_yesno(msg: str, default: bool = None, meta_dict: t.Dict[str, str] = None) -> bool:
"""
Prompt for simple yes or no decision.
:param msg: asked question
:param default: default value
:param meta_dict: mapping 'yes' or 'no' to further explanations
:return: user input converted to bool
"""
valid_words = ["yes", "no", "y", "n"]
if default is not None:
msg += "[" + ("y" if default else "n") + "] "
valid_words.append("")
completer = WordCompleter(["yes", "no"], ignore_case=True, meta_dict=meta_dict)
text = prompt(msg, completer=completer, display_completions_in_columns=True,
validator=WordValidator(valid_words, ignore_case=True))
if text == "":
return default
return text.lower().startswith("y")
评论列表
文章目录