Skip to content

Improper formatting of the questionary.select default choice #473

@LeoTN

Description

@LeoTN

Describe the problem

Hi, I’ve been experimenting with the selection menu and its default option. For example, consider this code:

import questionary as qy

choices = [
    "Option 1",
    "Default Option",
    "Option 3",
]

style = qy.Style(
    [
        # Better visibility for the selected option
        ("highlighted", "fg:red"),
    ]
)

qy.select(
    message="Selection with a default option:",
    choices=choices,
    default=choices[1],
    style=style,
).ask()

The menu opens with the second option selected by default, which works as intended. However, the selected option is rendered using the inverted style and does not visually update when the focus changes.

Image

Expanding the style parameter does not seem to work either:

style = qy.Style(
    [
        # Better visibility for the selected option
        ("highlighted", "fg:red"),
        ("selected", "noreverse"),
    ]
)

Image

Describe the solution

Changing select.py like this seems to fix the issue, but I am not entirely sure why:

ic = InquirerControl(
        choices,
        # default,
        pointer=pointer,
        use_indicator=use_indicator,
        use_shortcuts=use_shortcuts,
        show_selected=show_selected,
        show_description=show_description,
        use_arrow_keys=use_arrow_keys,
        initial_choice=default,
)

Image

Alternatives considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions