1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
package huh
import (
catppuccin "github.com/catppuccin/go"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/lipgloss"
)
// Theme is a collection of styles for components of the form.
// Themes can be applied to a form using the WithTheme option.
type Theme struct {
Form lipgloss.Style
Group lipgloss.Style
FieldSeparator lipgloss.Style
Blurred FieldStyles
Focused FieldStyles
Help help.Styles
}
// FieldStyles are the styles for input fields.
type FieldStyles struct {
Base lipgloss.Style
Title lipgloss.Style
Description lipgloss.Style
ErrorIndicator lipgloss.Style
ErrorMessage lipgloss.Style
// Select styles.
SelectSelector lipgloss.Style // Selection indicator
Option lipgloss.Style // Select options
NextIndicator lipgloss.Style
PrevIndicator lipgloss.Style
// FilePicker styles.
Directory lipgloss.Style
File lipgloss.Style
// Multi-select styles.
MultiSelectSelector lipgloss.Style
SelectedOption lipgloss.Style
SelectedPrefix lipgloss.Style
UnselectedOption lipgloss.Style
UnselectedPrefix lipgloss.Style
// Textinput and teatarea styles.
TextInput TextInputStyles
// Confirm styles.
FocusedButton lipgloss.Style
BlurredButton lipgloss.Style
// Card styles.
Card lipgloss.Style
NoteTitle lipgloss.Style
Next lipgloss.Style
}
// TextInputStyles are the styles for text inputs.
type TextInputStyles struct {
Cursor lipgloss.Style
CursorText lipgloss.Style
Placeholder lipgloss.Style
Prompt lipgloss.Style
Text lipgloss.Style
}
const (
buttonPaddingHorizontal = 2
buttonPaddingVertical = 0
)
// ThemeBase returns a new base theme with general styles to be inherited by
// other themes.
func ThemeBase() *Theme {
var t Theme
t.FieldSeparator = lipgloss.NewStyle().SetString("\n\n")
button := lipgloss.NewStyle().
Padding(buttonPaddingVertical, buttonPaddingHorizontal).
MarginRight(1)
// Focused styles.
t.Focused.Base = lipgloss.NewStyle().PaddingLeft(1).BorderStyle(lipgloss.ThickBorder()).BorderLeft(true)
t.Focused.Card = lipgloss.NewStyle().PaddingLeft(1)
t.Focused.ErrorIndicator = lipgloss.NewStyle().SetString(" *")
t.Focused.ErrorMessage = lipgloss.NewStyle().SetString(" *")
t.Focused.SelectSelector = lipgloss.NewStyle().SetString("> ")
t.Focused.NextIndicator = lipgloss.NewStyle().MarginLeft(1).SetString("→")
t.Focused.PrevIndicator = lipgloss.NewStyle().MarginRight(1).SetString("←")
t.Focused.MultiSelectSelector = lipgloss.NewStyle().SetString("> ")
t.Focused.SelectedPrefix = lipgloss.NewStyle().SetString("[•] ")
t.Focused.UnselectedPrefix = lipgloss.NewStyle().SetString("[ ] ")
t.Focused.FocusedButton = button.Foreground(lipgloss.Color("0")).Background(lipgloss.Color("7"))
t.Focused.BlurredButton = button.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("0"))
t.Focused.TextInput.Placeholder = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
t.Help = help.New().Styles
// Blurred styles.
t.Blurred = t.Focused
t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder())
t.Blurred.MultiSelectSelector = lipgloss.NewStyle().SetString(" ")
t.Blurred.NextIndicator = lipgloss.NewStyle()
t.Blurred.PrevIndicator = lipgloss.NewStyle()
return &t
}
// ThemeCharm returns a new theme based on the Charm color scheme.
func ThemeCharm() *Theme {
t := ThemeBase()
var (
normalFg = lipgloss.AdaptiveColor{Light: "235", Dark: "252"}
indigo = lipgloss.AdaptiveColor{Light: "#5A56E0", Dark: "#7571F9"}
cream = lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}
fuchsia = lipgloss.Color("#F780E2")
green = lipgloss.AdaptiveColor{Light: "#02BA84", Dark: "#02BF87"}
red = lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}
)
t.Focused.Base = t.Focused.Base.BorderForeground(lipgloss.Color("238"))
t.Focused.Title = t.Focused.Title.Foreground(indigo).Bold(true)
t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(indigo).Bold(true).MarginBottom(1)
t.Focused.Directory = t.Focused.Directory.Foreground(indigo)
t.Focused.Description = t.Focused.Description.Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"})
t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red)
t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red)
t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(fuchsia)
t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(fuchsia)
t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(fuchsia)
t.Focused.Option = t.Focused.Option.Foreground(normalFg)
t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(fuchsia)
t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green)
t.Focused.SelectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#02CF92", Dark: "#02A877"}).SetString("✓ ")
t.Focused.UnselectedPrefix = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"}).SetString("• ")
t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(normalFg)
t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(cream).Background(fuchsia)
t.Focused.Next = t.Focused.FocusedButton
t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(normalFg).Background(lipgloss.AdaptiveColor{Light: "252", Dark: "237"})
t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(green)
t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(lipgloss.AdaptiveColor{Light: "248", Dark: "238"})
t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(fuchsia)
t.Blurred = t.Focused
t.Blurred.Base = t.Focused.Base.BorderStyle(lipgloss.HiddenBorder())
t.Blurred.NextIndicator = lipgloss.NewStyle()
t.Blurred.PrevIndicator = lipgloss.NewStyle()
return t
}
// ThemeDracula returns a new theme based on the Dracula color scheme.
func ThemeDracula() *Theme {
t := ThemeBase()
var (
background = lipgloss.AdaptiveColor{Dark: "#282a36"}
selection = lipgloss.AdaptiveColor{Dark: "#44475a"}
foreground = lipgloss.AdaptiveColor{Dark: "#f8f8f2"}
comment = lipgloss.AdaptiveColor{Dark: "#6272a4"}
green = lipgloss.AdaptiveColor{Dark: "#50fa7b"}
purple = lipgloss.AdaptiveColor{Dark: "#bd93f9"}
red = lipgloss.AdaptiveColor{Dark: "#ff5555"}
yellow = lipgloss.AdaptiveColor{Dark: "#f1fa8c"}
)
t.Focused.Base = t.Focused.Base.BorderForeground(selection)
t.Focused.Title = t.Focused.Title.Foreground(purple)
t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(purple)
t.Focused.Description = t.Focused.Description.Foreground(comment)
t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red)
t.Focused.Directory = t.Focused.Directory.Foreground(purple)
t.Focused.File = t.Focused.File.Foreground(foreground)
t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red)
t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(yellow)
t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(yellow)
t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(yellow)
t.Focused.Option = t.Focused.Option.Foreground(foreground)
t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(yellow)
t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green)
t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(green)
t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(foreground)
t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(comment)
t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(yellow).Background(purple).Bold(true)
t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(foreground).Background(background)
t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(yellow)
t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(comment)
t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(yellow)
t.Blurred = t.Focused
t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder())
t.Blurred.NextIndicator = lipgloss.NewStyle()
t.Blurred.PrevIndicator = lipgloss.NewStyle()
return t
}
// ThemeBase16 returns a new theme based on the base16 color scheme.
func ThemeBase16() *Theme {
t := ThemeBase()
t.Focused.Base = t.Focused.Base.BorderForeground(lipgloss.Color("8"))
t.Focused.Title = t.Focused.Title.Foreground(lipgloss.Color("6"))
t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(lipgloss.Color("6"))
t.Focused.Directory = t.Focused.Directory.Foreground(lipgloss.Color("6"))
t.Focused.Description = t.Focused.Description.Foreground(lipgloss.Color("8"))
t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(lipgloss.Color("9"))
t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(lipgloss.Color("9"))
t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(lipgloss.Color("3"))
t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(lipgloss.Color("3"))
t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(lipgloss.Color("3"))
t.Focused.Option = t.Focused.Option.Foreground(lipgloss.Color("7"))
t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(lipgloss.Color("3"))
t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(lipgloss.Color("2"))
t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(lipgloss.Color("2"))
t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(lipgloss.Color("7"))
t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("5"))
t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(lipgloss.Color("7")).Background(lipgloss.Color("0"))
t.Focused.TextInput.Cursor.Foreground(lipgloss.Color("5"))
t.Focused.TextInput.Placeholder.Foreground(lipgloss.Color("8"))
t.Focused.TextInput.Prompt.Foreground(lipgloss.Color("3"))
t.Blurred = t.Focused
t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder())
t.Blurred.NoteTitle = t.Blurred.NoteTitle.Foreground(lipgloss.Color("8"))
t.Blurred.Title = t.Blurred.NoteTitle.Foreground(lipgloss.Color("8"))
t.Blurred.TextInput.Prompt = t.Blurred.TextInput.Prompt.Foreground(lipgloss.Color("8"))
t.Blurred.TextInput.Text = t.Blurred.TextInput.Text.Foreground(lipgloss.Color("7"))
t.Blurred.NextIndicator = lipgloss.NewStyle()
t.Blurred.PrevIndicator = lipgloss.NewStyle()
return t
}
// ThemeCatppuccin returns a new theme based on the Catppuccin color scheme.
func ThemeCatppuccin() *Theme {
t := ThemeBase()
light := catppuccin.Latte
dark := catppuccin.Mocha
var (
base = lipgloss.AdaptiveColor{Light: light.Base().Hex, Dark: dark.Base().Hex}
text = lipgloss.AdaptiveColor{Light: light.Text().Hex, Dark: dark.Text().Hex}
subtext1 = lipgloss.AdaptiveColor{Light: light.Subtext1().Hex, Dark: dark.Subtext1().Hex}
subtext0 = lipgloss.AdaptiveColor{Light: light.Subtext0().Hex, Dark: dark.Subtext0().Hex}
overlay1 = lipgloss.AdaptiveColor{Light: light.Overlay1().Hex, Dark: dark.Overlay1().Hex}
overlay0 = lipgloss.AdaptiveColor{Light: light.Overlay0().Hex, Dark: dark.Overlay0().Hex}
green = lipgloss.AdaptiveColor{Light: light.Green().Hex, Dark: dark.Green().Hex}
red = lipgloss.AdaptiveColor{Light: light.Red().Hex, Dark: dark.Red().Hex}
pink = lipgloss.AdaptiveColor{Light: light.Pink().Hex, Dark: dark.Pink().Hex}
mauve = lipgloss.AdaptiveColor{Light: light.Mauve().Hex, Dark: dark.Mauve().Hex}
cursor = lipgloss.AdaptiveColor{Light: light.Rosewater().Hex, Dark: dark.Rosewater().Hex}
)
t.Focused.Base = t.Focused.Base.BorderForeground(subtext1)
t.Focused.Title = t.Focused.Title.Foreground(mauve)
t.Focused.NoteTitle = t.Focused.NoteTitle.Foreground(mauve)
t.Focused.Directory = t.Focused.Directory.Foreground(mauve)
t.Focused.Description = t.Focused.Description.Foreground(subtext0)
t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.Foreground(red)
t.Focused.ErrorMessage = t.Focused.ErrorMessage.Foreground(red)
t.Focused.SelectSelector = t.Focused.SelectSelector.Foreground(pink)
t.Focused.NextIndicator = t.Focused.NextIndicator.Foreground(pink)
t.Focused.PrevIndicator = t.Focused.PrevIndicator.Foreground(pink)
t.Focused.Option = t.Focused.Option.Foreground(text)
t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.Foreground(pink)
t.Focused.SelectedOption = t.Focused.SelectedOption.Foreground(green)
t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.Foreground(green)
t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.Foreground(text)
t.Focused.UnselectedOption = t.Focused.UnselectedOption.Foreground(text)
t.Focused.FocusedButton = t.Focused.FocusedButton.Foreground(base).Background(pink)
t.Focused.BlurredButton = t.Focused.BlurredButton.Foreground(text).Background(base)
t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.Foreground(cursor)
t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.Foreground(overlay0)
t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.Foreground(pink)
t.Blurred = t.Focused
t.Blurred.Base = t.Blurred.Base.BorderStyle(lipgloss.HiddenBorder())
t.Help.Ellipsis = t.Help.Ellipsis.Foreground(subtext0)
t.Help.ShortKey = t.Help.ShortKey.Foreground(subtext0)
t.Help.ShortDesc = t.Help.ShortDesc.Foreground(overlay1)
t.Help.ShortSeparator = t.Help.ShortSeparator.Foreground(subtext0)
t.Help.FullKey = t.Help.FullKey.Foreground(subtext0)
t.Help.FullDesc = t.Help.FullDesc.Foreground(overlay1)
t.Help.FullSeparator = t.Help.FullSeparator.Foreground(subtext0)
return t
}
|