Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_blank_line_fix():
def get_prompt_tokens():
return [("class:question", "What is your favourite letter?")]
ic = InquirerControl(["a", "b", "c"])
inp = create_pipe_input()
try:
inp.send_text("")
layout = common.create_inquirer_layout(
ic, get_prompt_tokens, input=inp, output=DummyOutput()
)
# usually this would be 2000000000000000000000000000000
# but `common._fix_unecessary_blank_lines` makes sure
# the main window is not as greedy (avoiding blank lines)
assert (
layout.container.preferred_height(100, 200).max
== 1000000000000000000000000000001
)
finally:
inp.close()
event.app.exit(result=[c.value for c in ic.get_selected_values()])
@bindings.add('o', eager=True)
def open_url(event: Any):
pkg = ic.get_pointed_at().pkg
if pkg:
import webbrowser
webbrowser.open(pkg.url)
@bindings.add(Keys.Any)
def other(event: Any):
# Disallow inserting other text
pass
layout = create_inquirer_layout(ic, get_prompt_tokens, **prompt_kwargs)
app = Application(layout=layout, key_bindings=bindings, style=qstyle, **prompt_kwargs)
return Question(app)
tokens.append(
("class:answer", " done ({} selections)".format(nbr_selected))
)
else:
tokens.append(
(
"class:instruction",
" (Use arrow keys to move, "
" to select, "
"<a> to toggle, "
"<i> to invert)",
)
)
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")
@bindings.add(" ", eager=True)
def toggle(event):
pointed_choice = ic.get_pointed_at().value
if pointed_choice in ic.selected_options:
ic.selected_options.remove(pointed_choice)
else:
ic.selected_options.append(pointed_choice)
</i></a>
import webbrowser
webbrowser.open(pkg.url)
@bindings.add('s', eager=True)
def skip(event: Any):
ic.pointed_at = -1
ic.is_answered = True
event.app.exit(result=ic.get_pointed_at().value)
@bindings.add(Keys.Any)
def other(event: Any):
# Disallow inserting other text
pass
layout = create_inquirer_layout(ic, get_prompt_tokens, **prompt_kwargs)
app = Application(layout=layout, key_bindings=bindings, style=qstyle, **prompt_kwargs)
return Question(app)
else:
tokens.append(("class:answer", " " + ic.get_pointed_at().title))
else:
if instruction:
tokens.append(("class:instruction", instruction))
else:
tokens.append(
(
"class:instruction",
" (Use shortcuts)" if use_shortcuts else " (Use arrow keys)",
)
)
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):