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
|
diff --git a/registry/prompt.go b/registry/prompt.go
index 73d733d5ef39a8d10a34466dc36cee43fefa9331..4bfcbc1a5a1543bddd8e2f1b7c9892303adc4b0a 100644
--- a/registry/prompt.go
+++ b/registry/prompt.go
@@ -10,10 +10,10 @@ "text/template"
"go.jolheiser.com/tmpl/config"
- "github.com/AlecAivazis/survey/v2"
+ "github.com/charmbracelet/huh"
)
-func prompt(dir string, defaults bool) (templatePrompts, error) {
+func prompt(dir string, defaults, accessible bool) (templatePrompts, error) {
templatePath := filepath.Join(dir, "tmpl.yaml")
fi, err := os.Open(templatePath)
if err != nil {
@@ -55,52 +55,48 @@ continue
}
// Otherwise, prompt
- var p survey.Prompt
+ var f huh.Field
switch prompt.Type {
case config.PromptTypeSelect:
- opts := make([]string, 0, len(prompt.Options))
+ opts := make([]huh.Option[string], 0, len(prompt.Options))
for idy, opt := range prompt.Options {
- opts[idy] = os.ExpandEnv(opt)
+ o := os.ExpandEnv(opt)
+ opts[idy] = huh.NewOption(o, o)
}
- p = &survey.Select{
- Message: prompt.Label,
- Options: opts,
- Help: prompt.Help,
- }
+ def := prompt.Default
+ f = huh.NewSelect[string]().
+ Title(prompt.Label).
+ Description(prompt.Help).
+ Options(opts...).
+ Key(prompt.ID).
+ Value(&def)
case config.PromptTypeConfirm:
def, _ := strconv.ParseBool(os.ExpandEnv(prompt.Default))
- p = &survey.Confirm{
- Message: prompt.Label,
- Help: prompt.Help,
- Default: def,
- }
- case config.PromptTypeMultiline:
- p = &survey.Multiline{
- Message: prompt.Label,
- Default: os.ExpandEnv(prompt.Default),
- Help: prompt.Help,
- }
- case config.PromptTypeEditor:
- p = &survey.Editor{
- Message: prompt.Label,
- Default: os.ExpandEnv(prompt.Default),
- Help: prompt.Help,
- }
+ f = huh.NewConfirm().
+ Title(prompt.Label).
+ Description(prompt.Help).
+ Key(prompt.ID).
+ Value(&def)
+ case config.PromptTypeMultiline, config.PromptTypeEditor:
+ def := os.ExpandEnv(prompt.Default)
+ f = huh.NewText().
+ Title(prompt.Label).
+ Description(prompt.Help).
+ Key(prompt.ID).
+ Value(&def)
default:
- p = &survey.Input{
- Message: prompt.Label,
- Default: os.ExpandEnv(prompt.Default),
- Help: prompt.Help,
- }
+ def := os.ExpandEnv(prompt.Default)
+ f = huh.NewInput().
+ Title(prompt.Label).
+ Description(prompt.Help).
+ Key(prompt.ID).
+ Value(&def)
}
-
- m := make(map[string]any)
- if err := survey.AskOne(p, &m); err != nil {
- return nil, fmt.Errorf("could not complete prompt: %w", err)
+ if err := huh.NewForm(huh.NewGroup(f)).WithAccessible(accessible).WithTheme(huh.ThemeCatppuccin()).Run(); err != nil {
+ return nil, fmt.Errorf("could not run field: %w", err)
}
- a := m[""]
- prompts[idx].Value = a
- os.Setenv(fmt.Sprintf("TMPL_PROMPT_%s", envKey), fmt.Sprint(a))
+ prompts[idx].Value = f.GetValue()
+ os.Setenv(fmt.Sprintf("TMPL_PROMPT_%s", envKey), fmt.Sprint(f.GetValue()))
}
return prompts, nil
|