| 71 | } |
| 72 | |
| 73 | func (p *huhPrompter) buildMultiSelectForm(prompt string, defaults []string, options []string) (*huh.Form, *[]int) { |
| 74 | var result []int |
| 75 | |
| 76 | defaults = slices.DeleteFunc(defaults, func(s string) bool { |
| 77 | return !slices.Contains(options, s) |
| 78 | }) |
| 79 | |
| 80 | formOptions := make([]huh.Option[int], len(options)) |
| 81 | for i, o := range options { |
| 82 | if slices.Contains(defaults, o) { |
| 83 | result = append(result, i) |
| 84 | } |
| 85 | formOptions[i] = huh.NewOption(o, i) |
| 86 | } |
| 87 | |
| 88 | form := p.newForm( |
| 89 | huh.NewGroup( |
| 90 | huh.NewMultiSelect[int](). |
| 91 | Title(prompt). |
| 92 | Value(&result). |
| 93 | Limit(len(options)). |
| 94 | Options(formOptions...), |
| 95 | ), |
| 96 | ) |
| 97 | return form, &result |
| 98 | } |
| 99 | |
| 100 | func (p *huhPrompter) MultiSelect(prompt string, defaults []string, options []string) ([]int, error) { |
| 101 | form, result := p.buildMultiSelectForm(prompt, defaults, options) |