diff --git a/.gitignore b/.gitignore index 9ed3b07..51a0d54 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.test +.idea/ \ No newline at end of file diff --git a/input.go b/input.go index 4e8e76a..cd6b815 100644 --- a/input.go +++ b/input.go @@ -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 diff --git a/select.go b/select.go index f334f65..c9e0e3c 100644 --- a/select.go +++ b/select.go @@ -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 }