[GH-ISSUE #940] How to change the color of a background of inputField #689

Open
opened 2026-03-04 01:07:03 +03:00 by kerem · 1 comment
Owner

Originally created by @BrunProgramming on GitHub (Jan 18, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/940

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

Originally created by @BrunProgramming on GitHub (Jan 18, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/940 and trying to change the background color of the Inputfield this is my code ```go 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
Author
Owner

@rivo commented on GitHub (Mar 5, 2024):

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.

<!-- gh-comment-id:1979695986 --> @rivo commented on GitHub (Mar 5, 2024): I guess [`SetFieldBackgroundColor`](https://pkg.go.dev/github.com/rivo/tview#Form.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`](https://pkg.go.dev/github.com/rivo/tview#Form.GetFormItem) after constructing the form, cast to an input field, then change its attributes.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#689
No description provided.