Skip to content

Commit

Permalink
feat: add search mode in goutils
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Mar 5, 2024
1 parent f58de74 commit b68b9cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
15 changes: 10 additions & 5 deletions common/goutils/cmd/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"slices"
"strconv"
"strings"

"github.com/chzyer/readline"
"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -217,11 +218,15 @@ func GetOptionFromPrompt[T any](flag OptionFlag[T]) (Option[T], error) {
}

prompt := promptui.Select{
Label: label,
Items: items,
Stdout: NoBellStdout,
Size: size,
CursorPos: cursorPos,
Label: label,
Items: items,
Stdout: NoBellStdout,
Size: size,
CursorPos: cursorPos,
StartInSearchMode: flag.StartInSearchMode,
Searcher: func(input string, index int) bool {
return strings.Contains(strings.ToLower(items[index]), input)
},
}
_, result, err := prompt.Run()
if err != nil {
Expand Down
19 changes: 10 additions & 9 deletions common/goutils/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ type Option[T any] interface {
}

type OptionFlag[T any] struct {
Name string
Short string
DefaultValue Option[T]
Options []Option[T]
Usage string
Prompt string
Required bool
ValidateFn func(input string) error
MaxSelectionSize uint
Name string
Short string
DefaultValue Option[T]
Options []Option[T]
Usage string
Prompt string
Required bool
ValidateFn func(input string) error
MaxSelectionSize uint
StartInSearchMode bool
}

0 comments on commit b68b9cb

Please sign in to comment.