rivo / tview

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

InputField placeholder text is word-wrapped #1001

Closed kivattt closed 2 months ago

kivattt commented 5 months 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 5 months 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?

kivattt commented 4 months ago

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