Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return tokens
layout = common.create_inquirer_layout(ic, get_prompt_tokens, **kwargs)
bindings = KeyBindings()
@bindings.add(Keys.ControlQ, eager=True)
@bindings.add(Keys.ControlC, eager=True)
def _(event):
event.app.exit(exception=KeyboardInterrupt, style="class:aborting")
if use_shortcuts:
# add key bindings for choices
for i, c in enumerate(ic.choices):
if isinstance(c, Separator):
continue
# noinspection PyShadowingNames
def _reg_binding(i, keys):
# trick out late evaluation with a "function factory":
# https://stackoverflow.com/a/3431699
@bindings.add(keys, eager=True)
def select_choice(event):
ic.pointed_at = i
_reg_binding(i, c.shortcut_key)
else:
@bindings.add(Keys.Down, eager=True)
@bindings.add("j", eager=True)
def move_cursor_down(event):
def all(event):
all_selected = True # all choices have been selected
for c in ic.choices:
if (
not isinstance(c, Separator)
and c.value not in ic.selected_options
and not c.disabled
):
# add missing ones
ic.selected_options.append(c.value)
all_selected = False
if all_selected:
ic.selected_options = []
def __init__(self, line: Optional[Text] = None):
"""Create a separator in a list.
Args:
line: Text to be displayed in the list, by default uses `---`.
"""
self.line = line or self.default_separator
super(Separator, self).__init__(self.line, None, "-")
def is_selection_a_separator(self):
selected = self.choices[self.pointed_at]
return isinstance(selected, Separator)
def invert(event: Any):
inverted_selection = [
c.value
for c in ic.choices
if not isinstance(c, Separator)
and c.value not in ic.selected_options
and not c.disabled
]
ic.selected_options = inverted_selection
def invert(event):
inverted_selection = [
c.value
for c in ic.choices
if not isinstance(c, Separator)
and c.value not in ic.selected_options
and not c.disabled
]
ic.selected_options = inverted_selection