-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (85 loc) · 2.31 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"os"
"strings"
"github.com/c-bata/go-prompt"
"github.com/jrecuero/go-cli/app/cli/prompt/commands"
"github.com/jrecuero/go-cli/prompter"
"github.com/jrecuero/go-cli/syntax"
"github.com/jrecuero/go-cli/tools"
"gopkg.in/AlecAivazis/survey.v1"
)
var p *prompt.Prompt
var livePrefixState struct {
livePrefix string
isEnable bool
}
func executor(in string) {
if in == "exit" || in == "quit" {
os.Exit(0)
}
tools.ToDisplay("Your input: " + in)
testArray := strings.Fields(in)
tools.ToDisplay("Number of tokens: ", len(testArray))
for _, v := range testArray {
tools.ToDisplay("token: " + v)
}
livePrefixState.livePrefix = in + "> "
livePrefixState.isEnable = true
}
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"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}
func changeLivePrefix() (string, bool) {
return livePrefixState.livePrefix, livePrefixState.isEnable
}
func runGoPrompt() {
tools.ToDisplay("Please select table.")
//t := prompt.Input("> ", completer)
//tools.ToDisplay("You selected " + t)
p = prompt.New(
executor,
completer,
prompt.OptionPrefix(syntax.DEFAULTPROMPT),
prompt.OptionLivePrefix(changeLivePrefix),
prompt.OptionTitle("cli-prompt"),
prompt.OptionHistory([]string{}),
prompt.OptionPrefixTextColor(prompt.Red),
prompt.OptionPreviewSuggestionTextColor(prompt.Blue),
prompt.OptionSelectedSuggestionBGColor(prompt.LightGray),
prompt.OptionSuggestionBGColor(prompt.DarkGray),
)
p.Run()
}
func runInputSurvey() {
name := ""
prompt := &survey.Input{
Message: "ping",
}
survey.AskOne(prompt, &name, nil)
}
func runMultiSelectSurvey() {
days := []string{}
prompt := &survey.MultiSelect{
Message: "What days do you prefer?",
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
}
survey.AskOne(prompt, &days, nil)
}
func runPrompter() {
//pr := &prompter.Prompter{}
pr := prompter.NewPrompter()
pr.Setup("prompter", commands.SetupCommands()...)
pr.Run()
}
func main() {
//runGoPrompt()
//runInputSurvey()
//runMultiSelectSurvey()
runPrompter()
}