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

Transformed answer not displayed after submitting input #449

Closed twelvelabs closed 1 year ago

twelvelabs commented 1 year ago

What operating system and terminal are you using?

An example that showcases the bug.

package main

import (
    "fmt"
    "strings"

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

func main() {
    qs := []*survey.Question{
        {
            Prompt: &survey.Input{
                Message: "Name",
            },
            Transform: survey.TransformString(strings.TrimSpace),
        },
    }
    name := ""
    _ = survey.Ask(qs, &name)

    fmt.Println("Hello,", name)
}

Ran the above and submitted:

            Skip

What did you expect to see?

[~/tmp] $ go run main.go 
? Name Skip
Hello, Skip

What did you see instead?

[~/tmp] $ go run main.go 
? Name             Skip
Hello, Skip

The transformed answer is passed to the prompt on Cleanup(), but appears to be ignored in favor of the input's existing answer:

https://github.com/AlecAivazis/survey/blob/bf4b865e6c271af51ee152a74e41a037d1f8b013/input.go#L211

Changing that to ans := val.(string) seems to fix the issue. I'll try writing a test case and submit a PR.