init.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:temci 作者: parttimenerd 项目源码 文件源码
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")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号