Debian Codegraph @

examples/theme/main.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 "os"
6
7 "github.com/charmbracelet/huh"
8 )
9
10 func main() {
11 var base *huh.Theme = huh.ThemeBase()
12 var dracula *huh.Theme = huh.ThemeDracula()
13 var base16 *huh.Theme = huh.ThemeBase16()
14 var charm *huh.Theme = huh.ThemeCharm()
15 var catppuccin *huh.Theme = huh.ThemeCatppuccin()
16 var exit *huh.Theme = nil
17
18 var theme *huh.Theme = base16
19
20 repeat := true
21
22 for {
23 err := huh.NewSelect[*huh.Theme]().
24 Title("Theme").
25 Value(&theme).
26 Options(
27 huh.NewOption("Default", base),
28 huh.NewOption("Dracula", dracula),
29 huh.NewOption("Base 16", base16),
30 huh.NewOption("Charm", charm),
31 huh.NewOption("Catppuccin", catppuccin),
32 huh.NewOption("Exit", exit),
33 ).Run()
34
35 if err != nil {
36 if err == huh.ErrUserAborted {
37 os.Exit(130)
38 }
39 fmt.Println(err)
40 os.Exit(1)
41 }
42 if theme == nil {
43 break
44 }
45
46 // Display form with selected theme.
47 err = huh.NewForm(
48 huh.NewGroup(
49 huh.NewInput().Title("Thoughts").Placeholder("What's on your mind?"),
50 huh.NewSelect[string]().Options(huh.NewOptions("A", "B", "C")...).Title("Colors"),
51 huh.NewFilePicker().Title("File"),
52 huh.NewMultiSelect[string]().Options(huh.NewOptions("Red", "Green", "Yellow")...).Title("Letters"),
53 huh.NewConfirm().Title("Again?").Description("Try another theme").Value(&repeat),
54 ),
55 ).WithTheme(theme).Run()
56 if err != nil {
57 if err == huh.ErrUserAborted {
58 os.Exit(130)
59 }
60 fmt.Println(err)
61 os.Exit(1)
62 }
63
64 if !repeat {
65 break
66 }
67 }
68 }