rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
10.33k stars 543 forks source link

InputField placeholder text is word-wrapped #1001

Open kivattt opened 4 days ago

kivattt commented 4 days ago

In my project using tview, I have an InputField with SetFieldWidth(45), with some placeholder text. I noticed when the second word in the placeholder was long enough, it would suddenly disappear and show only the first word!

This code demonstrates the issue:

package main

import "github.com/rivo/tview"

func main() {
        inputField := tview.NewInputField().SetFieldWidth(45)

        // The placeholder will only show "This is a sentence with a very"
        inputField.SetPlaceholder("This is a sentence with a very looooooooooooooooooooong word")

        if err := tview.NewApplication().SetRoot(inputField, true).Run(); err != nil {
                panic(err)
        }
}

InputField uses a TextArea to draw the placeholder https://github.com/rivo/tview/blob/c38c796625fb04d2e677f0e737e42b079a8731ca/inputfield.go#L475

Which uses a TextView with word-wrapping enabled by default https://github.com/rivo/tview/blob/c38c796625fb04d2e677f0e737e42b079a8731ca/textarea.go#L1325-L1326

If this is intended behaviour, it would be nice to have something like .SetWrap() or .SetWordWrap() as part of InputField

rivo commented 2 days ago

So you would like to see partial words in the placeholder text? I wonder what the rationale is for that. Consider this example:

"Would you like some ass" ("...istance?")

I'm not sure that this would be good for the user.

Maybe you can explain why you'd want this?