tmbo / questionary

Python library to build pretty command line user prompts ✨Easy to use multi-select lists, confirmations, free text prompts ...
MIT License
1.57k stars 90 forks source link

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

Open Arpafaucon opened 1 year ago

Arpafaucon commented 1 year ago

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 ! :heart:

Context

I have implemented a form using questionary with 2 questions

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

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

Investigation

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

Latest version

Questionary version

2.0.1

Prompt Toolkit version

3.0.36

Operating System

Linux