Debian Codegraph @

option.go

raw symbols SCIP
1 package huh
2
3 import "fmt"
4
5 // Option is an option for select fields.
6 type Option[T comparable] struct {
7 Key string
8 Value T
9 selected bool
10 }
11
12 // NewOptions returns new options from a list of values.
13 func NewOptions[T comparable](values ...T) []Option[T] {
14 options := make([]Option[T], len(values))
15 for i, o := range values {
16 options[i] = Option[T]{
17 Key: fmt.Sprint(o),
18 Value: o,
19 }
20 }
21 return options
22 }
23
24 // NewOption returns a new select option.
25 func NewOption[T comparable](key string, value T) Option[T] {
26 return Option[T]{Key: key, Value: value}
27 }
28
29 // Selected sets whether the option is currently selected.
30 func (o Option[T]) Selected(selected bool) Option[T] {
31 o.selected = selected
32 return o
33 }
34
35 // String returns the key of the option.
36 func (o Option[T]) String() string {
37 return o.Key
38 }