Debian Codegraph @

theme.go

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