AlecAivazis / survey

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

Previous terminal line is removed when answer is string longer than 80 chars #347

Open dmartin35 opened 3 years ago

dmartin35 commented 3 years ago

When prompting for a answer, if the response contains 80+ characters, the previous line in the terminal disappear / is removed

What operating system and terminal are you using? seen on mac os x with default terminal and vscode terminal

An example that showcases the bug.

package main

import (
    "fmt"

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

func main() {
    fmt.Println("This message should not be removed even if anwser has length >= 80 chars")

    var (
        r1 string
    )

    _ = survey.AskOne(&survey.Input{
        Message: "Enter a very long response",
    }, &r1)

    fmt.Println("response: ", r1)

}

What did you expect to see?

$ go run question.go 
This message should not be removed even if anwser has length >= 80 chars
? Enter a very long response 01234567890123456789012345678901234567890123456789012345678901234567890123456789
response:  01234567890123456789012345678901234567890123456789012345678901234567890123456789

What did you see instead?

$ go run question.go 
? Enter a very long response 01234567890123456789012345678901234567890123456789012345678901234567890123456789
response:  01234567890123456789012345678901234567890123456789012345678901234567890123456789
dmartin35 commented 3 years ago

I have added a runtime stack trace , when the https://github.com/AlecAivazis/survey/blob/c79c4a988cde2621cf87a59265233ed7e9e0b63e/terminal/cursor.go#L49 function is called

runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/Cellar/go/1.15.3/libexec/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
        /usr/local/Cellar/go/1.15.3/libexec/src/runtime/debug/stack.go:16 +0x25
github.com/AlecAivazis/survey/v2/terminal.(*Cursor).PreviousLine(0xc0001e57e0, 0x1)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/terminal/cursor.go:58 +0x157
github.com/AlecAivazis/survey/v2.(*Renderer).resetPrompt(0xc0001d4000, 0x1)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/renderer.go:115 +0x205
github.com/AlecAivazis/survey/v2.(*Renderer).Render(0xc0001d4000, 0x118978c, 0x493, 0x1171f00, 0xc0001b1040, 0x0, 0x0)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/renderer.go:75 +0xa8
github.com/AlecAivazis/survey/v2.(*Input).OnChange(0xc0001d4000, 0xc000000073, 0xc0001d6048, 0x0, 0x0, 0x0)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/input.go:119 +0x235
github.com/AlecAivazis/survey/v2.(*Input).Prompt(0xc0001d4000, 0xc0001d6048, 0x0, 0x0, 0x0, 0x0)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/input.go:169 +0x2fa
github.com/AlecAivazis/survey/v2.Ask(0xc0001e5eb0, 0x1, 0x1, 0x114faa0, 0xc000188430, 0x0, 0x0, 0x0, 0x0, 0x118a290)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/survey.go:295 +0x55e
github.com/AlecAivazis/survey/v2.AskOne(0x11b3120, 0xc0001d4000, 0x114faa0, 0xc000188430, 0x0, 0x0, 0x0, 0x1005dc5, 0xc00006c058)
        /Users/dmartin/go/src/github.com/AlecAivazis/survey/survey.go:238 +0x12d
main.main()

don't know if that could help for investigation