Skip to content

Extra choice info for select/fuzzy #55

@Gracecr

Description

@Gracecr

Similar to #41, I'm looking to provide extra information about the choices. Currently I'm using including this info in Choice.name, but this messes with fuzzy.

Perhaps I could change the long instruction on "hover"?

Here's a simplified example:

import dataclasses

from InquirerPy import inquirer
from InquirerPy.base.control import Choice


@dataclasses.dataclass
class Fruit:
    name: str
    description: str


fruits = [
    Fruit(
        "Apple",
        "A common, round fruit produced by the tree Malus domestica, cultivated in temperate climates.",
    ),
    Fruit(
        "Bananna",
        "A banana is an elongated, edible fruit - botanically a berry - produced by several kinds of large herbaceous flowering plants in the genus Musa.",
    ),
    Fruit(
        "Peach",
        "The peach (Prunus persica) is a deciduous tree first domesticated and cultivated in Zhejiang province of Eastern China.",
    ),
]

max_name_len = max(len(f.name) for f in fruits)
choices = [Choice(f, f.name.ljust(max_name_len + 1) + f.description) for f in fruits]

inquirer.fuzzy("Pick a fruit", choices).execute()

tmp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions