manifoldco / promptui

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

Prompts filling the terminal width causes bad UI #92

Open maraino opened 5 years ago

maraino commented 5 years ago

Description

When a prompt and the user input fills the terminal width and the input has to go to the next line, the prompt is written again in a new line.

In a small terminal, the proof of concept bellow will cause multiple lines like:

$ go run longprompt.go
✔ Please enter a long very long answer so it has to go to the next line: abcdefg
✔ Please enter a long very long answer so it has to go to the next line: abcdefg
✔ Please enter a long very long answer so it has to go to the next line: abcdefg
hi

Proof of concept:

package main

import (
    "fmt"

    "github.com/manifoldco/promptui"
)

func main() {

    prompt := promptui.Prompt{
        Label: "Please enter a long very long answer so it has to go to the next line",
    }

    result, err := prompt.Run()
    if err != nil {
        fmt.Printf("Prompt failed %v\n", err)
        return
    }
    fmt.Printf("You choose %q\n", result)
}
MondayHopscotch commented 5 years ago

I am running into the same thing. It looks like for every character that is past the end of the width of the terminal, it prints a new prompt line. In your example, hi were the extra characters, so you got 2 extra lines. I have a much longer string and it's dumping out a ton of lines. (We are expecting users to copy/paste a long string into the terminal)

shaneharter commented 5 years ago

I ran into this, too. It's being caused by line wrapping in the terminal.

After a little research, there isn't a perfect way to disable this, but I've made the issue better in many (most?) modern terminals by disabling wrapping:

https://github.com/shaneharter/promptui/commit/33d9dc105f3f49679d8cec3544835fdf5be3612e

I've not raised a PR because it seems a bit of a hack