CITGuru / PyInquirer

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

Disabled options that are first in a choice list are selectable initially, when they should not be. #78

Open alichtman opened 4 years ago

alichtman commented 4 years ago

Here's a minimal demo of the bug.

from PyInquirer import prompt, style_from_dict, Token, Separator

custom_style_2 = style_from_dict({
    Token.Separator: '#6C6C6C',
    Token.QuestionMark: '#FF9D00 bold',
    # Token.Selected: '',  # default
    Token.Selected: '#5F819D',
    Token.Pointer: '#FF9D00 bold',
    Token.Instruction: '',  # default
    Token.Answer: '#5F819D bold',
    Token.Question: '',
})

def buggy_prompt():
    choices = [
        Separator(),
        # This should not be selectable, but it is.
        {
             'name': 'Attach to existing tmux session',
             'disabled': 'Select one below.'
        },
        "Should be first choice."
    ]

    questions = [
        {
            'type': 'list',
            'name': 'action',
            'message': 'What do you want to do?',
            'choices': choices
        },
    ]

    answers = prompt(questions, style=custom_style_2)
    print(answers)
    return None

def main():
    buggy_prompt()

if __name__ == "__main__":
    main()
image

My guess is that some logic to check if the first choice in the list is "disabled" when placing the selection cursor would fix this. The bug is somewhere in this file: https://github.com/CITGuru/PyInquirer/blob/master/PyInquirer/prompts/list.py