rivo / tview

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

How to change the color of a background of inputField #940

Open BrunProgramming opened 10 months ago

BrunProgramming commented 10 months ago

and trying to change the background color of the Inputfield this is my code

package main

import (
    "github.com/rivo/tview"
)

var name string
var github string

var space = "═══════════════════════════════════"

func main() {
    app := tview.NewApplication()

    form := tview.NewForm().
        AddTextView("[#7D56F4]ʘ‿ʘ[white]", `Hellooo what is the name of your project?`, 40, 2, true, true).
    AddInputField("[#FEBB00]name", "[:red]", 20, func(textToCheck string, lastChar rune) bool {
            name = textToCheck
            return true
        }, nil).
    AddInputField("[#FEBB00]github repository:", "", 20, func(textToCheck string, lastChar rune) bool {
            github = textToCheck
            return true
        }, nil)
    form.AddButton("[#7D56F4]ʘ‿ʘ:Ready?", func() {
        app.Stop()
  })
    form.SetBorder(true).SetTitle(space + "Goxt cli").SetTitleAlign(tview.AlignLeft)
    if err := app.SetRoot(form, true).EnableMouse(true).Run(); err != nil {
        panic(err)
    }
}

I would appreciate anyone's help thanks

rivo commented 8 months ago

I guess SetFieldBackgroundColor is what you're looking for.

But if you want to change the colour of only one of the input fields, you'd probably have to use GetFormItem after constructing the form, cast to an input field, then change its attributes.