Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithTheme doesn't seem to change the theme #100

Closed
dfalgout opened this issue Jan 15, 2024 · 11 comments
Closed

WithTheme doesn't seem to change the theme #100

dfalgout opened this issue Jan 15, 2024 · 11 comments

Comments

@dfalgout
Copy link

dfalgout commented Jan 15, 2024

First, thank you all for the incredible hard work and nice design of the charm.sh suite. I'm hella diggin' it!

When I attempt to change the theme of a huh Form with .WithTheme() the form style is unchanged from the default theme.
Not only colors not changing, but also any block formatting, etc.

err = huh.NewMultiSelect[*App]().
  Options(options...).
  Title("Select Apps to stop").
  Value(&selectedApps).
  WithTheme(CustomTheme()).
  Run()

In the example screenshot below, I am also printing out the theme items and see changes in those elements, but no change in the actual form theme.
Screenshot 2024-01-14 at 11 08 27 PM

@maaslalani
Copy link
Contributor

Thanks so much for reporting this issue @dfalgout, I will take a look.

@testinfected
Copy link

@dfalgout I had the same issue and workaround was to define the form myself, set form theme then add the widget to the form

@meowgorithm
Copy link
Member

Off the cuff, I'd guess that this is only happening on one-off elements, i.e.

huh.NewMultiSelect().
    WithTheme(customTheme()).
    Run()

Whereas the following works in my testing:

huh.NewForm().
    WithTheme(customTheme()).
    Run()

@caarlos0
Copy link
Member

my guess its a similar problem to #97

@jolheiser
Copy link
Contributor

jolheiser commented Jan 24, 2024

This is indeed semi-specific to using fields directly, but it's only because they use the global Run internally, which is the source of the issue.

In order from call site:

return Run(m)

huh/run.go

Line 6 in 9cd22a8

form := NewForm(group).WithShowHelp(false)

huh/form.go

Lines 72 to 84 in 9cd22a8

f := &Form{
groups: groups,
paginator: p,
theme: ThemeCharm(),
keymap: NewDefaultKeyMap(),
width: 0,
height: 0,
results: make(map[string]any),
}
// NB: If dynamic forms come into play this will need to be applied when
// groups and fields are added.
f.WithTheme(f.theme)

huh/form.go

Lines 225 to 227 in 9cd22a8

for _, group := range f.groups {
group.WithTheme(theme)
}

huh/group.go

Lines 95 to 97 in 9cd22a8

for _, field := range g.fields {
field.WithTheme(t)
}

@maaslalani
Copy link
Contributor

I believe this issue should be solved if we simply check if the theme or keymap is already set on the field before overriding it. This will make things work individually and allow changing themes / keymaps for individual fields as part of a larger form as well.

@maaslalani
Copy link
Contributor

This should be fixed by #123, let us know if this works for you!

If it doesn't please feel free to re-open this issue or create a new one!

@zx8
Copy link

zx8 commented Apr 15, 2024

@maaslalani Can this be re-opened? It seems #123 was reverted by commit 51377e6, so this is still an issue.

@mrkwtz
Copy link

mrkwtz commented May 4, 2024

Can confirm with 0.30.0 it's still an issue, please re-open.

@maaslalani maaslalani reopened this May 4, 2024
@maaslalani
Copy link
Contributor

Apologies! Thanks for letting us know, re-opened the issue for now.

@maaslalani
Copy link
Contributor

Okay after a bunch of testing I believe I have solved it correctly this time, please do try it out and let me know if everything works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants