Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.test
.idea/
4 changes: 4 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ type Options struct {
// By default, MaskVal is asterisk(*).
MaskVal string

// ReturnIndex is used to return the index instead of the value when using Select.
// By default, ReturnIndex is false.
ReturnIndex bool

// ValidateFunc is function to do extra validation of user
// input string. By default, it does nothing (just returns nil).
ValidateFunc ValidateFunc
Expand Down
10 changes: 9 additions & 1 deletion select.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)
}

// Reach here means it gets ideal input.
resultStr = list[n-1]

// Check if the return will be the value or the index.
returnIndex := opts.ReturnIndex
if !returnIndex {
resultStr = list[n-1]
} else {
resultStr = line
}

break
}

Expand Down