Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
multiple items, use `Choice("foo", checked=True)` instead.
qmark: Question prefix displayed in front of the question.
By default this is a `?`
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
use_pointer: Flag to enable the pointer in front of the currently
highlighted element.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
merged_style = merge_styles([DEFAULT_STYLE, style])
ic = InquirerControl(choices, default, use_pointer=use_pointer)
def get_prompt_tokens():
tokens = []
tokens.append(("class:qmark", qmark))
tokens.append(("class:question", " {} ".format(message)))
if ic.is_answered:
nbr_selected = len(ic.selected_options)
if nbr_selected == 0:
tokens.append(("class:answer", " done"))
elif nbr_selected == 1:
if isinstance(ic.get_selected_values()[0].title, list):
tokens.append(
(
message: Question text
default: Default value will be returned if the user just hits
enter.
qmark: Question prefix displayed in front of the question.
By default this is a `?`
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
merged_style = merge_styles([DEFAULT_STYLE, style])
status = {"answer": None}
def get_prompt_tokens():
tokens = []
tokens.append(("class:qmark", qmark))
tokens.append(("class:question", " {} ".format(message)))
if status["answer"] is not None:
answer = " {}".format(YES if status["answer"] else NO)
tokens.append(("class:answer", answer))
else:
instruction = " {}".format(YES_OR_NO if default else NO_OR_YES)
tokens.append(("class:instruction", instruction))
This can either be a function accepting the input and
returning a boolean, or an class reference to a
subclass of the prompt toolkit Validator class.
qmark: Question prefix displayed in front of the question.
By default this is a `?`
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
merged_style = merge_styles([DEFAULT_STYLE, style])
validator = build_validator(validate)
def get_prompt_tokens() -> List[Tuple[Text, Text]]:
return [("class:qmark", qmark), ("class:question", " {} ".format(message))]
p = PromptSession(
get_prompt_tokens, style=merged_style, validator=validator, **kwargs
)
p.default_buffer.reset(Document(default))
return Question(p.app)
This can either be a function accepting the input and
returning a boolean, or an class reference to a
subclass of the prompt toolkit Validator class.
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
if not choices:
raise ValueError("No choices is given, you should use Text question.")
merged_style = merge_styles([DEFAULT_STYLE, style])
def get_prompt_tokens() -> List[Tuple[Text, Text]]:
return [("class:qmark", qmark), ("class:question", " {} ".format(message))]
def get_meta_style(meta: Dict[Text, Any]):
if meta:
for key in meta:
meta[key] = HTML("").format(meta[key])
return meta
validator = build_validator(validate)
if completer is None:
# use the default completer
completer = WordCompleter(
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
if choices is None or len(choices) == 0:
raise ValueError("A list of choices needs to be provided.")
if use_shortcuts and len(choices) > len(InquirerControl.SHORTCUT_KEYS):
raise ValueError(
"A list with shortcuts supports a maximum of {} "
"choices as this is the maximum number "
"of keyboard shortcuts that are available. You"
"provided {} choices!"
"".format(len(InquirerControl.SHORTCUT_KEYS), len(choices))
)
merged_style = merge_styles([DEFAULT_STYLE, style])
ic = InquirerControl(
choices,
default,
use_indicator=use_indicator,
use_shortcuts=use_shortcuts,
use_pointer=use_pointer,
)
def get_prompt_tokens():
# noinspection PyListCreation
tokens = [("class:qmark", qmark), ("class:question", " {} ".format(message))]
if ic.is_answered:
if isinstance(ic.get_pointed_at().title, list):
tokens.append(