| 1 |
package huh |
| 2 |
|
| 3 |
import "fmt" |
| 4 |
|
| 5 |
|
| 6 |
type Option[T comparable] struct { |
| 7 |
Key string |
| 8 |
Value T |
| 9 |
selected bool |
| 10 |
} |
| 11 |
|
| 12 |
|
| 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 |
|
| 25 |
func NewOption[T comparable](key string, value T) Option[T] { |
| 26 |
return Option[T]{Key: key, Value: value} |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
func (o Option[T]) Selected(selected bool) Option[T] { |
| 31 |
o.selected = selected |
| 32 |
return o |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
func (o Option[T]) String() string { |
| 37 |
return o.Key |
| 38 |
} |