go-prompt/main.go

58 lines
1.0 KiB
Go
Raw Normal View History

2017-07-05 15:59:22 +00:00
package main
import (
"fmt"
"github.com/c-bata/go-prompt-toolkit/prompt"
)
2017-07-15 08:37:54 +00:00
func executor(b *prompt.Buffer) string {
2017-07-15 13:23:47 +00:00
r := "Your input: " + b.Text()
2017-07-15 08:37:54 +00:00
return r
2017-07-14 01:50:35 +00:00
}
2017-07-15 08:37:54 +00:00
func completer(b *prompt.Buffer) []string {
2017-07-15 11:22:56 +00:00
if w := b.Document().GetWordBeforeCursor(); w == "" {
return []string{}
} else {
2017-07-15 16:04:18 +00:00
if []rune(w)[0] == []rune("s")[0] {
return []string{"select"}
} else if []rune(w)[0] == []rune("w")[0] {
return []string{"where"}
} else if []rune(w)[0] == []rune("d")[0] {
return []string{"drop", "delete"}
} else if []rune(w)[0] == []rune("f")[0] {
return []string{"from"}
}
}
return []string{
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
"select",
2017-07-15 11:22:56 +00:00
}
2017-07-05 15:59:22 +00:00
}
2017-07-14 01:51:19 +00:00
2017-07-15 08:37:54 +00:00
func main() {
2017-07-16 08:20:58 +00:00
pt := prompt.NewPrompt(
executor,
completer,
prompt.MaxCompletionsOption(8),
prompt.PrefixOption("> "),
)
2017-07-15 08:37:54 +00:00
defer fmt.Println("\nGoodbye!")
2017-07-15 13:23:47 +00:00
fmt.Print("Hello! This is a example appication using prompt-toolkit.\n")
2017-07-15 08:37:54 +00:00
pt.Run()
2017-07-14 01:51:19 +00:00
}