Skip to content

Commit 6cf5337

Browse files
committed
Added WithInitialIndex to sdk/picker
1 parent 60959cd commit 6cf5337

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sdk/picker/picker.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type picker struct {
1616
actions []action
1717
options []option
1818
filtered []*option
19+
initialIndex int
1920
selectedIndex int
2021
term string
2122
filterStrategy string
@@ -44,6 +45,7 @@ func NewPicker() *picker {
4445
actions: []action{},
4546
options: []option{},
4647
filtered: []*option{},
48+
initialIndex: 0,
4749
selectedIndex: 0,
4850
title: "Please Pick One",
4951
term: "",
@@ -76,6 +78,10 @@ func (p *picker) WithTitle(title string) {
7678
p.title = title
7779
}
7880

81+
func (p *picker) WithInitialIndex(index int) {
82+
p.initialIndex = index
83+
}
84+
7985
func (p *picker) WithHeaders(headers ...string) {
8086
p.headers = headers
8187
for i, header := range headers {
@@ -220,6 +226,11 @@ func (p *picker) render() {
220226
func (p *picker) Pick(initialFilter string) (*option, *keys.KeyCode) {
221227
p.term = initialFilter
222228
p.filter()
229+
if len( p.filtered ) > p.initialIndex {
230+
p.selectedIndex = p.initialIndex
231+
} else {
232+
p.selectedIndex = 0
233+
}
223234
ansi.HideCursor()
224235
defer ansi.ClearDown()
225236
defer ansi.ShowCursor()

0 commit comments

Comments
 (0)