File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ type picker struct {
16
16
actions []action
17
17
options []option
18
18
filtered []* option
19
+ initialIndex int
19
20
selectedIndex int
20
21
term string
21
22
filterStrategy string
@@ -44,6 +45,7 @@ func NewPicker() *picker {
44
45
actions : []action {},
45
46
options : []option {},
46
47
filtered : []* option {},
48
+ initialIndex : 0 ,
47
49
selectedIndex : 0 ,
48
50
title : "Please Pick One" ,
49
51
term : "" ,
@@ -76,6 +78,10 @@ func (p *picker) WithTitle(title string) {
76
78
p .title = title
77
79
}
78
80
81
+ func (p * picker ) WithInitialIndex (index int ) {
82
+ p .initialIndex = index
83
+ }
84
+
79
85
func (p * picker ) WithHeaders (headers ... string ) {
80
86
p .headers = headers
81
87
for i , header := range headers {
@@ -220,6 +226,11 @@ func (p *picker) render() {
220
226
func (p * picker ) Pick (initialFilter string ) (* option , * keys.KeyCode ) {
221
227
p .term = initialFilter
222
228
p .filter ()
229
+ if len ( p .filtered ) > p .initialIndex {
230
+ p .selectedIndex = p .initialIndex
231
+ } else {
232
+ p .selectedIndex = 0
233
+ }
223
234
ansi .HideCursor ()
224
235
defer ansi .ClearDown ()
225
236
defer ansi .ShowCursor ()
You can’t perform that action at this time.
0 commit comments