Skip to content

Commit

Permalink
Merge pull request #13 from liamg/owenr-allow-preselection
Browse files Browse the repository at this point in the history
feat: support preselection
  • Loading branch information
Owen Rumney committed Oct 27, 2023
2 parents dafff3a + dc452cc commit be5d3ae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions prompt/multiSelectList.go
Expand Up @@ -52,6 +52,22 @@ func ChooseFromMultiList(message string, options []string, colourOverrides ...st
return getListSelection(message, items)
}

func ChooseFromPreselectedMultiList(message string, options []string, colourOverrides ...string) ([]int, []string, error) {
if len(options) == 0 {
return nil, nil, ErrNoOptionsProvided
}
var items []*listItem
colours := []string{"lightblue", "lightgreen", "lightyellow", "white"}
if len(colourOverrides) > 0 {
colours = colourOverrides
}
for index, option := range options {
col := colours[index%len(colours)]
items = append(items, &listItem{index: index, value: option, selected: true, colour: col})
}
return getListSelection(message, items)
}

func getListSelection(message string, items []*listItem) ([]int, []string, error) {
fmt.Printf("\n %s\n\r", message)
currentPos := 0
Expand Down

0 comments on commit be5d3ae

Please sign in to comment.