-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Autocomplete prompt #196
Comments
@Whoaa512 this can be done by setting |
2 tasks
For some reason, that search option doesn't work for me. It makes a "search bar" to show but I' m unable to type anything on it. Do you have a working example? |
I've got a working example that implements a simple "fuzzy search". It's not perfect but will get you going: package main
import (
"fmt"
"regexp"
"github.com/manifoldco/promptui"
)
func simpleRegexSearcher(items []string) func(input string, index int) bool {
return func(input string, index int) bool {
reg, _ := regexp.Compile(fmt.Sprintf("(?i).*%s.*", input))
return reg.MatchString(items[index])
}
}
func main() {
items := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
prompt := promptui.Select{
StartInSearchMode: true,
Label: "Select Day",
Items: items,
Searcher: simpleRegexSearcher(items),
}
_, result, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
fmt.Printf("You choose %q\n", result)
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey thanks so much for building this useful library! I'm coming from a JS/TS world and specifically have used a package called
prompts
in the past and I'd love to see anautocomplete
promptThis would be quite similar to the Select already available but wouldn't require the user to hit a key to get into search mode. Searching would be the default and pressing arrow keys would automatically move the selection cursor.
Happy to make a PR but wanted to check if this would be something you'd accept and what approach would be preferable in implementing it. Like should it be implemented as a wholly new prompt or should it try to re-use the internals of Select as much as possible?
The text was updated successfully, but these errors were encountered: