manifoldco / promptui

Interactive prompt for command-line applications
https://www.manifold.co
BSD 3-Clause "New" or "Revised" License
6.03k stars 333 forks source link

select captures previous enter key as input #184

Open joshuamarquez opened 3 years ago

joshuamarquez commented 3 years ago

before select is executed, if enter key is pressed this one will be captured as input for select misleading to undesired behavior.

code to reproduce

package main

import (
    "fmt"
    "time"
    "github.com/manifoldco/promptui"
)

func main() {
    fmt.Println("press 'enter key' to reproduce behaviour")
    time.Sleep(5000 * time.Millisecond)

    prompt := promptui.Select{
        Label: "Select Day",
        Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"},
    }

    _, result, err := prompt.Run()

    if err != nil {
        fmt.Printf("Prompt failed %v\n", err)
        return
    }

    fmt.Printf("You choose %q\n", result)
}
Screen Shot 2021-06-16 at 11 36 09