Debian Codegraph @

examples/accessibility-secure-input/main.go

raw symbols SCIP
1 package main
2
3 import (
4 "errors"
5 "log"
6
7 "github.com/charmbracelet/huh"
8 )
9
10 func validate(s string) error {
11 if s == "" {
12 return errors.New("input cannot be empty")
13 }
14 return nil
15 }
16
17 func main() {
18 form := huh.NewForm(
19 huh.NewGroup(
20 huh.NewNote().
21 Title("Welcome!").
22 Description("This is an accessible form example!"),
23 huh.NewInput().
24 Validate(validate).
25 Title("Name:"),
26 huh.NewInput().
27 EchoMode(huh.EchoModePassword).
28 Validate(validate).
29 Title("Password:"),
30 huh.NewMultiSelect[string]().
31 Options(huh.NewOptions(
32 "Red",
33 "Green",
34 "Yellow",
35 )...).
36 Limit(2).
37 Title("Choose some colors:"),
38 huh.NewSelect[string]().
39 Options(huh.NewOptions(
40 "Red",
41 "Green",
42 "Yellow",
43 )...).
44 Title("Choose the best color:"),
45 huh.NewFilePicker().
46 Title("Which file?"),
47 huh.NewConfirm().
48 Title("Send something?"),
49 ),
50 ).WithAccessible(true)
51
52 err := form.Run()
53 if err != nil {
54 log.Fatal(err)
55 }
56 }