Skip to content

Instantly share code, notes, and snippets.

@rnrbarbosa
Created February 25, 2024 10:58
Show Gist options
  • Save rnrbarbosa/dea40cad1d392027a0ba08e21e88d9be to your computer and use it in GitHub Desktop.
Save rnrbarbosa/dea40cad1d392027a0ba08e21e88d9be to your computer and use it in GitHub Desktop.
BubbleTea Snippets
type MyOption struct {
options []huh.Option[string]
}
func (o *MyOption) Options(options ...huh.Option[string]) {
o.options = options
}
var BurgerList = []string{"Charmburger Classic", "Chickwich", "Fishburger", "Charmpossible™ Burger"}
func makeBurgerOptions(l []string) MyOption {
myopt := make([]huh.Option[string], len(l))
for i, v := range l {
myopt[i] = huh.NewOption(v, v)
}
return MyOption{options: myopt}
}
form := huh.NewForm(
huh.NewGroup(huh.NewNote().
Title("Charmburger").
Description("Welcome to _Charmburger™_.\n\nHow may we take your order?")),
// Choose a burger.
// We'll need to know what topping to add too.
huh.NewGroup(
huh.NewSelect[string]().
Options(huh.NewOptions("Charmburger Classic", "Chickwich", "Fishburger", "Charmpossible™ Burger")...).
Title("Choose your burger").
Description("At Charm we truly have a burger for everyone.").
Validate(func(t string) error {
if t == "Fishburger" {
return fmt.Errorf("no fish today, sorry")
}
return nil
}).
Value(&order.Burger.Type),
huh.NewMultiSelect[string]().
Title("Toppings").
Description("Choose up to 4.").
Options(
makeBurgerOptions(BurgerList).options...
).
Value(&order.Burger.Toppings).
Filterable(true).
Limit(4),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment