Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating a checkbox with Alt-Enter makes it return the empty string #324

Open
1 task done
Arpafaucon opened this issue Oct 6, 2023 · 0 comments
Open
1 task done
Labels
Bug Something isn't working

Comments

@Arpafaucon
Copy link

Arpafaucon commented Oct 6, 2023

Describe the bug

First of all: thanks for maintaining this package ! I was veeery happy when I managed to make it work, and it saved us a lot of time by making multiple python scripts intuitively interactive ! ❤️

Context

I have implemented a form using questionary with 2 questions

  • a multi-line text prompt (that you have to validate with Alt-Enter )
  • a checkbox presenting a set of tags

When my users want to go too fast, they press Alt-Enter twice and this trigger a strange behavior

  • the first time validates the multi-line text prompt
  • so the checkbox form is shown
  • the second time is caught by the checkbox form
  • and it reacts by returning the empty string ''

We noticed this because the empty string is not even a list, so code breaks further down

Investigation

  • bug appears on versions 1.10.0 and 2.0.1
  • I had a look at the source code, trying to find how the keybinding logic works
    • I don't see any reference to either <Enter> or <Alt-Enter> in questionary code - but I might be looking for the wrong patterns
    • With a grep "Alt+Enter" -R in the prompt toolkit source code , I see that there are some emacs keybing config. However, the bug persists with use_emacs_keys=False

Example

import questionary

q = questionary.checkbox("Press Alt-Enter here", choices=[
    questionary.Choice(a, value=a)
    for a in "abc"
]).ask()

print(repr(q))

Steps to reproduce

  1. Write down the script above in a file, and run it
  2. When shown the checkbox form, select whatever choices you like
  3. Instead of pressing <Enter> to validate it
    • press <Alt-Enter>
    • OR press <Esc> then <Enter>
  4. On my machine, this will exit the checkbox form and print(repr(q)) will print ''

Expected behaviour

  • <Alt-Enter>/ <Esc + Enter> should not trigger any reaction
  • or it should behave like <Enter> and return the currently selected list
  • or raise an exception ?

Latest version

  • I have checked that this issue occurs on the latest version of questionary.

Questionary version

2.0.1

Prompt Toolkit version

3.0.36

Operating System

Linux

@Arpafaucon Arpafaucon added the Bug Something isn't working label Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant