multiSelectSearchField is a custom huh Field that combines a text input for searching with a multi-select list. Unlike huh's built-in OptionsFunc, search results are loaded synchronously when the user presses Enter in the search input, avoiding goroutine races with selection state.
| 18 | // search results are loaded synchronously when the user presses Enter in |
| 19 | // the search input, avoiding goroutine races with selection state. |
| 20 | type multiSelectSearchField struct { |
| 21 | // configuration |
| 22 | title string |
| 23 | searchTitle string |
| 24 | searchFunc func(string) MultiSelectSearchResult |
| 25 | |
| 26 | // state |
| 27 | mode msMode // which sub-component has focus |
| 28 | search textinput.Model |
| 29 | cursor int |
| 30 | loading bool |
| 31 | spinner spinner.Model |
| 32 | |
| 33 | // options and selections |
| 34 | options []msOption |
| 35 | selected map[string]bool // key → selected (source of truth) |
| 36 | optionLabels map[string]string // key → display label |
| 37 | lastQuery string |
| 38 | defaultValues []string |
| 39 | persistent []string |
| 40 | |
| 41 | // field metadata |
| 42 | key string |
| 43 | err error |
| 44 | focused bool |
| 45 | width int |
| 46 | height int |
| 47 | theme huh.Theme |
| 48 | hasDarkBg bool |
| 49 | position huh.FieldPosition |
| 50 | } |
| 51 | |
| 52 | type msMode int |
| 53 |
nothing calls this directly
no outgoing calls
no test coverage detected