CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.92k stars 236 forks source link

Default is ignored on lists #17

Closed martenjacobs closed 5 years ago

martenjacobs commented 5 years ago

It seems that the default-key is ignored on list-type questions

Consider the following code:

from PyInquirer import prompt, print_json

answer = prompt({
        'type': 'list',
        'name': "test-question",
        'message': "Select item",
        'default': 2,
        'choices': [
            {   "name"  : "Item 1",
                "value" : "item1"   },
            {   "name"  : "Item 2",
                "value" : "item2"   },
            {   "name"  : "Item 3",
                "value" : "item3"   },
            {   "name"  : "Item 4",
                "value" : "item4"   },
        ]
    })

print_json(answer)

Expected result:

Item 3 is initially selected in the prompt

Actual result:

Item 1 is initially selected in the prompt

Environment:

OS: macOS 10.14 Mojave

$ python3 --version
Python 3.6.1
$ python3 -m pip show PyInquirer
Name: PyInquirer
Version: 1.0.2
Summary: A Python module for collection of common interactive command line user interfaces, based on Inquirer.js
Home-page: https://github.com/CITGuru/PyInquirer/
Author: Oyetoke Toby
Author-email: oyetoketoby80@gmail.com
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requires: prompt-toolkit, Pygments, regex
Required-by:
CITGuru commented 5 years ago

I'll take a closer look at this.

CITGuru commented 5 years ago

Yes its actually ignored cos, you have to choose one from the list.

martenjacobs commented 5 years ago

From documentation it appears you should be able to define the initially selected list item. Either the documentation should be clarified or this feature should be implemented.

ajdavis commented 4 years ago

I believe this issue should be reopened, it's still present in version 1.0.3 on PyPI and on master.

ewels commented 4 years ago

Looks like this has now been fixed in #68 - we just need a release (#90)