AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.07k stars 349 forks source link

Support for `fmt.Stringer` interface to display structs in `Select`/`MultiSelect` #472

Open metafates opened 1 year ago

metafates commented 1 year ago

Awesome lib! But I really miss such behaviour, it would make things much easier.

Title says it's all, but just for the reference

type User struct {
    name, surname string
}

func (u *User) String() string {
    return fmt.Sprintf("%s %s", u.name, u.surname)
}

var users = []User{
    {"John", "Doe"},
    {"Sam", "Smith"},
}

func main() {
    var selected User
    survey.AskOne(&survey.Select{
        Message: "Select user",
        Options:   users,
    }, &selected)
}

This feature would make such operations much more convenient and optimised, rather than manually searching for a related data based on string somehow.

Are there any reasons why it's not a thing?

sad cat