2021-10-06 17:38:00 +00:00
|
|
|
package pick
|
|
|
|
|
|
|
|
type StringsSlice struct {
|
2022-01-27 12:29:49 +00:00
|
|
|
s []string
|
|
|
|
p *picker
|
2021-10-06 17:38:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewStringsSlice creates new StringsSlice.
|
|
|
|
func NewStringsSlice(items []string, mode pickMode) *StringsSlice {
|
2022-01-27 12:29:49 +00:00
|
|
|
return &StringsSlice{s: items, p: NewPicker(uint32(len(items)-1), mode)}
|
2021-10-06 17:38:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pick an element from the strings slice.
|
|
|
|
func (s *StringsSlice) Pick() string {
|
2022-01-27 12:29:49 +00:00
|
|
|
if len(s.s) == 0 {
|
2021-10-06 17:38:00 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-01-27 12:29:49 +00:00
|
|
|
return s.s[s.p.NextIndex()]
|
2021-10-06 17:38:00 +00:00
|
|
|
}
|