| 114 | } |
| 115 | |
| 116 | func (p *accessiblePrompter) Select(prompt, defaultValue string, options []string) (int, error) { |
| 117 | var result int |
| 118 | |
| 119 | // Remove invalid default values from the defaults slice. |
| 120 | if !slices.Contains(options, defaultValue) { |
| 121 | defaultValue = "" |
| 122 | } |
| 123 | |
| 124 | prompt = p.addDefaultsToPrompt(prompt, []string{defaultValue}) |
| 125 | formOptions := []huh.Option[int]{} |
| 126 | for i, o := range options { |
| 127 | // If this option is the default value, assign its index |
| 128 | // to the result variable. huh will treat it as a default selection. |
| 129 | if defaultValue == o { |
| 130 | result = i |
| 131 | } |
| 132 | formOptions = append(formOptions, huh.NewOption(o, i)) |
| 133 | } |
| 134 | |
| 135 | form := p.newForm( |
| 136 | huh.NewGroup( |
| 137 | huh.NewSelect[int](). |
| 138 | Title(prompt). |
| 139 | Value(&result). |
| 140 | Options(formOptions...), |
| 141 | ), |
| 142 | ) |
| 143 | |
| 144 | err := form.Run() |
| 145 | return result, err |
| 146 | } |
| 147 | |
| 148 | func (p *accessiblePrompter) MultiSelect(prompt string, defaults []string, options []string) ([]int, error) { |
| 149 | var result []int |