Skip to content

Instantly share code, notes, and snippets.

@AspenJames
Last active April 28, 2022 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AspenJames/970a014033b1adb695b65c9fffe1c428 to your computer and use it in GitHub Desktop.
Save AspenJames/970a014033b1adb695b65c9fffe1c428 to your computer and use it in GitHub Desktop.
Reproduce c-bata/go-prompt issue #253
package main
import (
"fmt"
"github.com/c-bata/go-prompt"
)
func completer(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "users", Description: "Store the username and age"},
{Text: "articles", Description: "Store the article text posted by user"},
{Text: "comments", Description: "Store the text commented to articles"},
{Text: "exit", Description: "Stop the looping!"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}
func main() {
for {
fmt.Println("Please select table.")
t := prompt.Input("> ", completer)
if t == "exit" {
break
}
fmt.Println("You selected " + t)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment