huh
huh copied to clipboard
Foreground color on any of the Focused.* fields do not apply
Describe the bug
When applying a color to any of the Theme.Focused.*
fields, the Foreground color doesn't hold. If I print the value with GetForeground()
function call, it shows lipgloss.NoColor
. However If I apply a Background color, it holds and shows accurately on the terminal.
To Reproduce
Reproduction code
package main
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)
func main() {
err := huh.NewForm(huh.NewGroup(
huh.NewNote().Title("Note").Description("Testing custom huh theme"),
huh.NewInput().Title("Input").Description("Please input something"),
huh.NewText().Title("Text").Description("Please add some text"),
huh.NewSelect[int]().Title("Select").Description("Please select single item").Options(
huh.NewOption("Option 1", 1),
huh.NewOption("Option 2", 2),
huh.NewOption("Option 3", 3),
huh.NewOption("Option 4", 4),
),
huh.NewMultiSelect[int]().Title("Multi select").
Description("Please select multiple").
Options(
huh.NewOption("Option 1", 1),
huh.NewOption("Option 2", 2),
huh.NewOption("Option 3", 3),
huh.NewOption("Option 4", 4),
),
huh.NewConfirm().Title("Confirm").Description("Please confirm"),
)).WithTheme(ThemeRosepine()).Run()
if err != nil {
return
}
fmt.Println("Hello from GoPlayground!")
}
// ThemeRosepine function
func ThemeRosepine() *huh.Theme {
t := huh.ThemeBase() // using any other theme apart from ThemeBase makes it work
var (
base = lipgloss.AdaptiveColor{Light: "#fafafa", Dark: "#0f111A"}
surface = lipgloss.AdaptiveColor{Light: "#fffaf3", Dark: "#1f1d2e"}
overlay = lipgloss.AdaptiveColor{Light: "#f2e9e1", Dark: "#26233a"}
muted = lipgloss.AdaptiveColor{Light: "#9893a5", Dark: "#6e6a86"}
subtle = lipgloss.AdaptiveColor{Light: "#797593", Dark: "#908caa"}
text = lipgloss.AdaptiveColor{Light: "#575279", Dark: "#e0def4"}
love = lipgloss.AdaptiveColor{Light: "#b4637a", Dark: "#eb6f92"}
gold = lipgloss.AdaptiveColor{Light: "#ea9d34", Dark: "#f6c177"}
rose = lipgloss.AdaptiveColor{Light: "#d7827e", Dark: "#ebbcba"}
pine = lipgloss.AdaptiveColor{Light: "#286983", Dark: "#31748f"}
foam = lipgloss.AdaptiveColor{Light: "#56949f", Dark: "#9ccfd8"}
iris = lipgloss.AdaptiveColor{Light: "#907aa9", Dark: "#c4a7e7"}
highlightLow = lipgloss.AdaptiveColor{Light: "#f4ede8", Dark: "#21202e"}
highlightMed = lipgloss.AdaptiveColor{Light: "#dfdad9", Dark: "#403d52"}
highlightHigh = lipgloss.AdaptiveColor{Light: "#cecacd", Dark: "#524f67"}
)
f := &t.Focused
f.Base.BorderForeground(muted).Background(base)
f.Title.Foreground(rose)
fmt.Printf("%+v %T\n", f.Title.GetForeground(), f.Title.GetForeground()) // {} lipgloss.NoColor
f.NoteTitle.Foreground(pine).Background(base)
fmt.Printf("%+v %T\n", f.Title.GetForeground(), f.NoteTitle.GetForeground()) // {} NoColor
f.Description.Foreground(subtle).Background(base)
f.ErrorIndicator.Foreground(rose).Background(base)
f.ErrorMessage.Foreground(love).Background(base)
f.SelectSelector.Foreground(pine).Background(base)
f.Option.Foreground(text).Background(base)
f.MultiSelectSelector.Foreground(text).Background(base)
f.SelectedOption.Foreground(foam).Background(base)
f.SelectedPrefix.Foreground(foam).Background(base)
f.UnselectedPrefix.Foreground(text).Background(base)
f.UnselectedOption.Foreground(text).Background(base)
f.FocusedButton.Foreground(base).Background(iris)
f.BlurredButton.Foreground(text).Background(surface)
f.TextInput.Cursor.Foreground(gold)
f.TextInput.Placeholder.Foreground(highlightMed)
f.TextInput.Prompt.Foreground(iris)
t.Blurred = *f
t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder())
t.Help.Ellipsis.Foreground(highlightLow)
t.Help.ShortKey.Foreground(muted)
t.Help.ShortDesc.Foreground(highlightHigh)
t.Help.ShortSeparator.Foreground(subtle)
t.Help.FullKey.Foreground(subtle)
t.Help.FullDesc.Foreground(overlay)
t.Help.FullSeparator.Foreground(subtle)
return t
}
Expected behavior
A call to lipgloss.Style.Foreground
should set the foreground color.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: ArchLinux
- Version: 6.8.8-arch1-1
Additional context
Trying to update themes other than huh.ThemeBase()
makes it work.
Instead of doing f.Title.Foreground(rose)
do f.Title = f.Title.Foreground(rose)
@dez11de that does work
Thanks @Chaitanyabsprip for the issue and thank you so much @dez11de for the help + solution ❤️