tview icon indicating copy to clipboard operation
tview copied to clipboard

InputField placeholder text is word-wrapped

Open kivattt opened this issue 1 year ago • 2 comments

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

kivattt avatar Jun 24 '24 16:06 kivattt

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?

rivo avatar Jun 26 '24 14:06 rivo

I agree that makes sense for most cases where you show normal text as words. I should have clarified that I am using an input field with a command as the placeholder where I do not want word-wrapping because it can hide arguments from the user image Notice the aqua colored text below the input field shows the start of a command argument, which isn't hinted at in the inputfield placeholder

kivattt avatar Jun 29 '24 12:06 kivattt