Debian Codegraph @

_examples/select_add/main.go

raw
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/manifoldco/promptui"
7 )
8
9 func main() {
10 items := []string{"Vim", "Emacs", "Sublime", "VSCode", "Atom"}
11 index := -1
12 var result string
13 var err error
14
15 for index < 0 {
16 prompt := promptui.SelectWithAdd{
17 Label: "What's your text editor",
18 Items: items,
19 AddLabel: "Other",
20 }
21
22 index, result, err = prompt.Run()
23
24 if index == -1 {
25 items = append(items, result)
26 }
27 }
28
29 if err != nil {
30 fmt.Printf("Prompt failed %v\n", err)
31 return
32 }
33
34 fmt.Printf("You choose %s\n", result)
35 }