AlecAivazis / survey

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

Survey failed to show output from fmt library #325

Closed Nnachevvv closed 2 years ago

Nnachevvv commented 3 years ago

What operating system and terminal are you using? Ubuntu 20.04.1 LTS (Focal Fossa) An example that showcases the bug.

package main

import (
    "fmt"

    "github.com/AlecAivazis/survey/v2"
)

// the questions to ask
var qs = []*survey.Question{
    {
        Name:      "name",
        Prompt:    &survey.Input{Message: "What is your name?"},
        Validate:  survey.Required,
        Transform: survey.Title,
    },
}

func main() {

    answers := struct {
        Name string // survey will match the question and field names
    }{}

    for apt := 0; apt < 3; apt++ {
        err := survey.Ask(qs, &answers)
        if err != nil {
            fmt.Println(err)
        }

        fmt.Println("failed to find this combination of name,color")
    }

}

What did you expect to see?


? What is your name? test
failed to find this combination of name,color
? What is your name? testtest
failed to find this combination of name,color
? What is your name? testtest
failed to find this combination of name,color

What did you see instead?

? What is your name? test
? What is your name? testtest
? What is your name? testtest
failed to find this combination of name,color

Version of library : github.com/AlecAivazis/survey/v2 v2.2.7

mislav commented 2 years ago

Duplicate of https://github.com/AlecAivazis/survey/issues/270

The workaround is to construct a new []*survey.Question{} struct for each iteration of the loop instead of reusing the same one.