| 146 | } |
| 147 | |
| 148 | func (p *accessiblePrompter) MultiSelect(prompt string, defaults []string, options []string) ([]int, error) { |
| 149 | var result []int |
| 150 | |
| 151 | // Remove invalid default values from the defaults slice. |
| 152 | defaults = slices.DeleteFunc(defaults, func(s string) bool { |
| 153 | return !slices.Contains(options, s) |
| 154 | }) |
| 155 | |
| 156 | prompt = p.addDefaultsToPrompt(prompt, defaults) |
| 157 | formOptions := make([]huh.Option[int], len(options)) |
| 158 | for i, o := range options { |
| 159 | // If this option is in the defaults slice, |
| 160 | // let's add its index to the result slice and huh |
| 161 | // will treat it as a default selection. |
| 162 | if slices.Contains(defaults, o) { |
| 163 | result = append(result, i) |
| 164 | } |
| 165 | |
| 166 | formOptions[i] = huh.NewOption(o, i) |
| 167 | } |
| 168 | |
| 169 | form := p.newForm( |
| 170 | huh.NewGroup( |
| 171 | huh.NewMultiSelect[int](). |
| 172 | Title(prompt). |
| 173 | Value(&result). |
| 174 | Limit(len(options)). |
| 175 | Options(formOptions...), |
| 176 | ), |
| 177 | ) |
| 178 | |
| 179 | if err := form.Run(); err != nil { |
| 180 | return nil, err |
| 181 | } |
| 182 | |
| 183 | return result, nil |
| 184 | } |
| 185 | |
| 186 | func (p *accessiblePrompter) Input(prompt, defaultValue string) (string, error) { |
| 187 | result := defaultValue |