-
Notifications
You must be signed in to change notification settings - Fork 322
Upgrade charmbracelet/huh to charm.land/huh/v2 v2.0.3 #24331
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,74 +3,74 @@ | |
| package styles | ||
|
|
||
| import ( | ||
| "github.com/charmbracelet/huh" | ||
| // huh v0.8.0 depends on charmbracelet/lipgloss v1, not charm.land/lipgloss/v2. | ||
| // This file intentionally uses the v1 import to match huh's type expectations. | ||
| "github.com/charmbracelet/lipgloss" | ||
| "charm.land/huh/v2" | ||
| "charm.land/lipgloss/v2" | ||
| ) | ||
|
|
||
| // HuhTheme returns a custom huh.Theme that maps the pkg/styles Dracula-inspired | ||
| // HuhTheme returns a huh.ThemeFunc that maps the pkg/styles Dracula-inspired | ||
| // color palette to huh form fields, giving interactive forms the same visual | ||
| // identity as the rest of the CLI output. | ||
| func HuhTheme() *huh.Theme { | ||
| t := huh.ThemeBase() | ||
| func HuhTheme() huh.ThemeFunc { | ||
| return func(isDark bool) *huh.Styles { | ||
| t := huh.ThemeBase(isDark) | ||
| lightDark := lipgloss.LightDark(isDark) | ||
|
Comment on lines
+10
to
+16
|
||
|
|
||
| // Map the pkg/styles palette to lipgloss.AdaptiveColor for huh compatibility. | ||
| // huh uses github.com/charmbracelet/lipgloss, so we use that type here. | ||
| var ( | ||
| primary = lipgloss.AdaptiveColor{Light: hexColorPurpleLight, Dark: hexColorPurpleDark} | ||
| success = lipgloss.AdaptiveColor{Light: hexColorSuccessLight, Dark: hexColorSuccessDark} | ||
| errorColor = lipgloss.AdaptiveColor{Light: hexColorErrorLight, Dark: hexColorErrorDark} | ||
| warning = lipgloss.AdaptiveColor{Light: hexColorWarningLight, Dark: hexColorWarningDark} | ||
| comment = lipgloss.AdaptiveColor{Light: hexColorCommentLight, Dark: hexColorCommentDark} | ||
| fg = lipgloss.AdaptiveColor{Light: hexColorForegroundLight, Dark: hexColorForegroundDark} | ||
| bg = lipgloss.AdaptiveColor{Light: hexColorBackgroundLight, Dark: hexColorBackgroundDark} | ||
| border = lipgloss.AdaptiveColor{Light: hexColorBorderLight, Dark: hexColorBorderDark} | ||
| ) | ||
| // Map the pkg/styles palette using lipgloss v2's LightDark helper. | ||
| var ( | ||
| primary = lightDark(lipgloss.Color(hexColorPurpleLight), lipgloss.Color(hexColorPurpleDark)) | ||
| success = lightDark(lipgloss.Color(hexColorSuccessLight), lipgloss.Color(hexColorSuccessDark)) | ||
| errorColor = lightDark(lipgloss.Color(hexColorErrorLight), lipgloss.Color(hexColorErrorDark)) | ||
| warning = lightDark(lipgloss.Color(hexColorWarningLight), lipgloss.Color(hexColorWarningDark)) | ||
| comment = lightDark(lipgloss.Color(hexColorCommentLight), lipgloss.Color(hexColorCommentDark)) | ||
| fg = lightDark(lipgloss.Color(hexColorForegroundLight), lipgloss.Color(hexColorForegroundDark)) | ||
| bg = lightDark(lipgloss.Color(hexColorBackgroundLight), lipgloss.Color(hexColorBackgroundDark)) | ||
| border = lightDark(lipgloss.Color(hexColorBorderLight), lipgloss.Color(hexColorBorderDark)) | ||
| ) | ||
|
|
||
| // Focused field styles | ||
| t.Focused.Base = t.Focused.Base.BorderForeground(border) | ||
| t.Focused.Card = t.Focused.Base | ||
| t.Focused.Title = t.Focused.Title.Foreground(primary).Bold(true) | ||
| t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(primary).Bold(true).MarginBottom(1) | ||
| t.Focused.Directory = t.Focused.Directory.Foreground(primary) | ||
| t.Focused.Description = t.Focused.Description.Foreground(comment) | ||
| t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(errorColor) | ||
| t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(errorColor) | ||
| // Focused field styles | ||
| t.Focused.Base = t.Focused.Base.BorderForeground(border) | ||
| t.Focused.Card = t.Focused.Base | ||
| t.Focused.Title = t.Focused.Title.Foreground(primary).Bold(true) | ||
| t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(primary).Bold(true).MarginBottom(1) | ||
| t.Focused.Directory = t.Focused.Directory.Foreground(primary) | ||
| t.Focused.Description = t.Focused.Description.Foreground(comment) | ||
| t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(errorColor) | ||
| t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(errorColor) | ||
|
|
||
| // Select / navigation indicators | ||
| t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(warning) | ||
| t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(warning) | ||
| t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(warning) | ||
| // Select / navigation indicators | ||
| t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(warning) | ||
| t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(warning) | ||
| t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(warning) | ||
|
|
||
| // List option styles | ||
| t.Focused.Option = t.Focused.Option.Foreground(fg) | ||
| t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(warning) | ||
| t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(success) | ||
| t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(success) | ||
| t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(fg) | ||
| t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(comment) | ||
| // List option styles | ||
| t.Focused.Option = t.Focused.Option.Foreground(fg) | ||
| t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(warning) | ||
| t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(success) | ||
| t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(success) | ||
| t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(fg) | ||
| t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(comment) | ||
|
|
||
| // Button styles | ||
| t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(bg).Background(primary).Bold(true) | ||
| t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(fg).Background(bg) | ||
| t.Focused.Next = t.Focused.FocusedButton | ||
| // Button styles | ||
| t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(bg).Background(primary).Bold(true) | ||
| t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(fg).Background(bg) | ||
| t.Focused.Next = t.Focused.FocusedButton | ||
|
|
||
| // Text input styles | ||
| t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(warning) | ||
| t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(comment) | ||
| t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(primary) | ||
| // Text input styles | ||
| t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(warning) | ||
| t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(comment) | ||
| t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(primary) | ||
|
|
||
| // Blurred styles mirror focused but hide the border | ||
| t.Blurred = t.Focused | ||
| t.Blurred.Base = t.Focused.Base.BorderStyle(lipgloss.HiddenBorder()) | ||
| t.Blurred.Card = t.Blurred.Base | ||
| t.Blurred.NextIndicator = lipgloss.NewStyle() | ||
| t.Blurred.PrevIndicator = lipgloss.NewStyle() | ||
| // Blurred styles mirror focused but hide the border | ||
| t.Blurred = t.Focused | ||
| t.Blurred.Base = t.Focused.Base.BorderStyle(lipgloss.HiddenBorder()) | ||
| t.Blurred.Card = t.Blurred.Base | ||
| t.Blurred.NextIndicator = lipgloss.NewStyle() | ||
| t.Blurred.PrevIndicator = lipgloss.NewStyle() | ||
|
|
||
| // Group header styles | ||
| t.Group.Title = t.Focused.Title | ||
| t.Group.Description = t.Focused.Description | ||
| // Group header styles | ||
| t.Group.Title = t.Focused.Title | ||
| t.Group.Description = t.Focused.Description | ||
|
|
||
| return t | ||
| return t | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
godirective was bumped from1.25.0to1.25.8, but the PR description only mentions the huh/lipgloss migration. If this bump is intentional (e.g., to match the toolchain used forgo mod tidy), please call it out in the PR description; otherwise consider reverting to avoid unnecessary version churn for consumers and CI images pinned to the previous patch level.