Add echo prompt example
This commit is contained in:
parent
b6ab262105
commit
97b6cde43a
36
_example/echo_prompt.go
Normal file
36
_example/echo_prompt.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/c-bata/go-prompt-toolkit/prompt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func executor(b *prompt.Buffer) string {
|
||||||
|
r := "Your input: " + b.Text()
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func completer(b *prompt.Buffer) []string {
|
||||||
|
if w := b.Document().GetWordBeforeCursor(); w == "" {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
return []string{
|
||||||
|
"users",
|
||||||
|
"sites",
|
||||||
|
"articles",
|
||||||
|
"comments",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pt := prompt.NewPrompt(
|
||||||
|
executor,
|
||||||
|
completer,
|
||||||
|
prompt.OptionMaxCompletions(8),
|
||||||
|
prompt.OptionPrefix(">>> "),
|
||||||
|
prompt.OptionTitle("SQLITE CLI"),
|
||||||
|
)
|
||||||
|
defer fmt.Println("\nGoodbye!")
|
||||||
|
pt.Run()
|
||||||
|
}
|
63
main.go
63
main.go
@ -1,63 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/c-bata/go-prompt-toolkit/prompt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func executor(b *prompt.Buffer) string {
|
|
||||||
r := "Your input: " + b.Text()
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func completer(b *prompt.Buffer) []string {
|
|
||||||
if w := b.Document().GetWordBeforeCursor(); w == "" {
|
|
||||||
return []string{}
|
|
||||||
} else {
|
|
||||||
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{
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffff",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pt := prompt.NewPrompt(
|
|
||||||
executor,
|
|
||||||
completer,
|
|
||||||
prompt.MaxCompletionsOption(8),
|
|
||||||
prompt.PrefixOption(">>> "),
|
|
||||||
prompt.TitleOption("SQLITE CLI"),
|
|
||||||
prompt.TextColorOption(prompt.Red),
|
|
||||||
prompt.ResultTextColorOption(prompt.DarkGray),
|
|
||||||
prompt.CompletedTextColorOption(prompt.Green),
|
|
||||||
prompt.CompletionTextColor(prompt.Black),
|
|
||||||
prompt.SelectedCompletionTextColor(prompt.White),
|
|
||||||
)
|
|
||||||
defer fmt.Println("\nGoodbye!")
|
|
||||||
fmt.Print("Hello! This is a example appication using prompt-toolkit.\n")
|
|
||||||
pt.Run()
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user