Skip to content

Commit 8079810

Browse files
author
mritd
committed
feat(prompt): 切换 提示库
切换 提示库 Signed-off-by: mritd <[email protected]>
1 parent 3a2aa41 commit 8079810

File tree

147 files changed

+1004
-11901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1004
-11901
lines changed

glide.lock

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import:
3030
version: d14193dfc626125c831501c1c42340b4248e1f5a
3131
- package: github.com/magiconair/properties
3232
version: 2c9e9502788518c97fe44e8955cd069417ee89df
33-
- package: github.com/manifoldco/promptui
34-
version: 8debffa8c66b4342872ef0465eee2aa01481849d
35-
subpackages:
36-
- list
37-
- screenbuf
3833
- package: github.com/mattn/go-colorable
3934
version: 7dc3415be66d7cc68bf0182f35c8d31f8d2ad8a7
4035
- package: github.com/mattn/go-isatty
@@ -43,8 +38,6 @@ import:
4338
version: b8bc1bf767474819792c23f32d8286a45736f1c6
4439
- package: github.com/mitchellh/mapstructure
4540
version: 00c29f56e2386353d58c599509e8dc3801b0d716
46-
- package: github.com/mritd/promptui
47-
version: f94fc11da389d3982f37aedc33706ec7e265c9f4
4841
- package: github.com/pelletier/go-toml
4942
version: 05bcc0fb0d3e60da4b8dd5bd7e0ea563eb4ca943
5043
- package: github.com/russross/blackfriday

pkg/commit/ci.go

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"text/template"
99

1010
"github.com/mritd/gitflow-toolkit/pkg/consts"
11-
gitprompt "github.com/mritd/gitflow-toolkit/pkg/prompt"
1211
"github.com/mritd/gitflow-toolkit/pkg/util"
13-
"github.com/mritd/promptui"
12+
"github.com/mritd/promptx"
1413
"github.com/pkg/errors"
1514
)
1615

@@ -43,48 +42,37 @@ func SelectCommitType() consts.CommitType {
4342
{Type: consts.PERF, ZHDescription: "性能优化", ENDescription: "Improving performance"},
4443
{Type: consts.EXIT, ZHDescription: "退出", ENDescription: "Exit commit"},
4544
}
46-
templates := &promptui.SelectTemplates{
47-
Label: "{{ . }}",
48-
Active: "❯ {{ .Type | cyan }} ({{ .ENDescription | cyan }})",
49-
Inactive: " {{ .Type | white }} ({{ .ENDescription | white }})",
50-
Selected: "{{ \"❯ Type:\" | green }} {{ .Type }}",
51-
Details: `
45+
cfg := &promptx.SelectConfig{
46+
ActiveTpl: "» {{ .Type | cyan }} ({{ .ENDescription | cyan }})",
47+
InactiveTpl: " {{ .Type | white }} ({{ .ENDescription | white }})",
48+
SelectPrompt: "Commit Type",
49+
SelectedTpl: "{{ \"» Type:\" | green }} {{ .Type }}",
50+
DisPlaySize: 9,
51+
DetailsTpl: `
5252
--------- Commit Type ----------
5353
{{ "Type:" | faint }} {{ .Type }}
5454
{{ "Description:" | faint }} {{ .ZHDescription }}({{ .ENDescription }})`,
5555
}
5656

57-
searcher := func(input string, index int) bool {
58-
commitType := commitTypes[index]
59-
cmType := strings.Replace(strings.ToLower(string(commitType.Type)), " ", "", -1)
60-
input = strings.Replace(strings.ToLower(input), " ", "", -1)
61-
62-
return strings.Contains(cmType, input)
63-
}
64-
65-
prompt := promptui.Select{
66-
Label: "Select Commit Type:",
67-
Items: commitTypes,
68-
Templates: templates,
69-
Size: 9,
70-
Searcher: searcher,
57+
s := &promptx.Select{
58+
Items: commitTypes,
59+
Config: cfg,
7160
}
7261

73-
i, _, err := prompt.Run()
74-
util.CheckAndExit(err)
62+
idx := s.Run()
7563

76-
if commitTypes[i].Type == consts.EXIT {
64+
if commitTypes[idx].Type == consts.EXIT {
7765
fmt.Println("Talk is cheap. Show me the code.")
7866
os.Exit(0)
7967
}
8068

81-
return commitTypes[i].Type
69+
return commitTypes[idx].Type
8270
}
8371

8472
// 输入影响范围
8573
func InputScope() string {
8674

87-
p := gitprompt.NewDefaultPrompt(func(line []rune) error {
75+
p := promptx.NewDefaultPrompt(func(line []rune) error {
8876
if strings.TrimSpace(string(line)) == "" {
8977
return errors.New("Input is empty!")
9078
} else {
@@ -99,7 +87,7 @@ func InputScope() string {
9987
// 输入提交主题
10088
func InputSubject() string {
10189

102-
p := gitprompt.NewDefaultPrompt(func(line []rune) error {
90+
p := promptx.NewDefaultPrompt(func(line []rune) error {
10391
if strings.TrimSpace(string(line)) == "" {
10492
return errors.New("Input is empty!")
10593
} else if len(line) > 25 {
@@ -115,7 +103,7 @@ func InputSubject() string {
115103
// 输入完整提交信息
116104
func InputBody() string {
117105

118-
p := gitprompt.NewDefaultPrompt(func(line []rune) error {
106+
p := promptx.NewDefaultPrompt(func(line []rune) error {
119107
return nil
120108
}, "Body:")
121109

@@ -130,7 +118,7 @@ func InputBody() string {
130118
// 输入提交关联信息
131119
func InputFooter() string {
132120

133-
p := gitprompt.NewDefaultPrompt(func(line []rune) error {
121+
p := promptx.NewDefaultPrompt(func(line []rune) error {
134122
return nil
135123
}, "Footer:")
136124

pkg/mergerequest/xmr.go

Lines changed: 63 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111
"github.com/mitchellh/go-homedir"
1212
"github.com/mritd/gitflow-toolkit/pkg/consts"
1313
"github.com/mritd/gitflow-toolkit/pkg/util"
14-
"github.com/mritd/promptui"
14+
"github.com/mritd/promptx"
1515
"github.com/spf13/viper"
1616
"github.com/xanzy/go-gitlab"
1717
)
1818

19+
const EmptyErrorMassage = "Input is empty!"
20+
1921
type Repository struct {
2022
Contributor string
2123
Token string
@@ -30,58 +32,52 @@ func ConfigRepository() *Repository {
3032

3133
repo := Repository{}
3234

33-
validate := func(input string) error {
34-
if strings.TrimSpace(input) == "" {
35-
return errors.New("subject is blank")
35+
// namespace/project
36+
p := promptx.NewDefaultPrompt(func(line []rune) error {
37+
if strings.TrimSpace(string(line)) == "" {
38+
return errors.New(EmptyErrorMassage)
39+
} else {
40+
return nil
3641
}
37-
return nil
38-
}
42+
}, "Project(eg: namespace/project):")
3943

40-
templates := &promptui.PromptTemplates{
41-
Prompt: "{{ . }} ",
42-
Valid: "{{ . | green }} ",
43-
Invalid: "{{ . | red }} ",
44-
Success: "{{ . | bold }} ",
45-
}
46-
47-
prompt := promptui.Prompt{
48-
Label: "❯ Project(eg: namespace/project):",
49-
Templates: templates,
50-
Validate: validate,
51-
}
52-
53-
project, err := prompt.Run()
54-
util.CheckAndExit(err)
44+
project := p.Run()
5545
repo.Project = strings.ToLower(project)
5646

57-
prompt = promptui.Prompt{
58-
Label: "❯ Contributor(eg: mritd):",
59-
Templates: templates,
60-
Validate: validate,
61-
}
47+
// Contributor
48+
p = promptx.NewDefaultPrompt(func(line []rune) error {
49+
if strings.TrimSpace(string(line)) == "" {
50+
return errors.New(EmptyErrorMassage)
51+
} else {
52+
return nil
53+
}
54+
}, "Contributor(eg: mritd):")
6255

63-
contributor, err := prompt.Run()
64-
util.CheckAndExit(err)
56+
contributor := p.Run()
6557
repo.Contributor = contributor
6658

67-
prompt = promptui.Prompt{
68-
Label: "❯ Token(eg: q6C49FK47WhU68ofb):",
69-
Templates: templates,
70-
Validate: validate,
71-
}
59+
// Token
60+
p = promptx.NewDefaultPrompt(func(line []rune) error {
61+
if strings.TrimSpace(string(line)) == "" {
62+
return errors.New(EmptyErrorMassage)
63+
} else {
64+
return nil
65+
}
66+
}, "Token(eg: q6C49FK47WhU68ofb):")
7267

73-
token, err := prompt.Run()
74-
util.CheckAndExit(err)
68+
token := p.Run()
7569
repo.Token = token
7670

77-
prompt = promptui.Prompt{
78-
Label: "❯ Address(eg: https://github.com):",
79-
Templates: templates,
80-
Validate: validate,
81-
}
71+
// Address
72+
p = promptx.NewDefaultPrompt(func(line []rune) error {
73+
if strings.TrimSpace(string(line)) == "" {
74+
return errors.New(EmptyErrorMassage)
75+
} else {
76+
return nil
77+
}
78+
}, "Address(eg: https://github.com):")
8279

83-
address, err := prompt.Run()
84-
util.CheckAndExit(err)
80+
address := p.Run()
8581
repo.Address = strings.ToLower(address)
8682

8783
if strings.Contains(repo.Address, "github.com") {
@@ -90,25 +86,18 @@ func ConfigRepository() *Repository {
9086
repo.Type = consts.GitLabRepo
9187
}
9288

93-
validate = func(input string) error {
94-
if strings.TrimSpace(input) == "" {
89+
// Automatic rebase
90+
p = promptx.NewDefaultPrompt(func(line []rune) error {
91+
if strings.TrimSpace(string(line)) == "" {
9592
return errors.New("subject is blank")
9693
}
97-
if strings.ToLower(strings.TrimSpace(input)) != "y" && strings.ToLower(strings.TrimSpace(input)) != "n" {
94+
if strings.ToLower(strings.TrimSpace(string(line))) != "y" && strings.ToLower(strings.TrimSpace(string(line))) != "n" {
9895
return errors.New("only enter y or n")
9996
}
10097
return nil
101-
}
98+
}, "Automatic rebase before merge request?(y/n)")
10299

103-
prompt = promptui.Prompt{
104-
Label: "❯ Automatic rebase before merge request?(y/n)",
105-
Templates: templates,
106-
Validate: validate,
107-
IsVimMode: true,
108-
}
109-
110-
autoRebase, err := prompt.Run()
111-
util.CheckAndExit(err)
100+
autoRebase := p.Run()
112101

113102
if strings.ToLower(strings.TrimSpace(autoRebase)) == "y" {
114103
repo.AutoRebase = true
@@ -161,38 +150,25 @@ func (repo *Repository) XMr() {
161150

162151
lastCommitInfo := *util.GetLastCommitInfo()
163152

164-
validate := func(input string) error {
165-
if strings.TrimSpace(input) == "" {
166-
return errors.New("target branch is blank")
153+
// Title
154+
prompt := promptx.NewDefaultPrompt(func(line []rune) error {
155+
if strings.TrimSpace(string(line)) == "" {
156+
return errors.New("Title is blank!")
167157
}
168158
return nil
169-
}
170-
171-
templates := &promptui.PromptTemplates{
172-
Prompt: "{{ . }} ",
173-
Valid: "{{ . | green }} ",
174-
Invalid: "{{ . | red }} ",
175-
Success: "{{ . | bold }} ",
176-
}
177-
178-
prompt := promptui.Prompt{
179-
Label: "❯ Title(eg: fix(v0.0.1):fix a bug):",
180-
Templates: templates,
181-
}
159+
}, "Title(eg: fix(v0.0.1):fix a bug):")
182160

183-
title, err := prompt.Run()
184-
util.CheckAndExit(err)
161+
title := prompt.Run()
185162
if strings.TrimSpace(title) == "" {
186163
title = lastCommitInfo[0]
187164
}
188165

189-
prompt = promptui.Prompt{
190-
Label: "❯ Description(eg: Rollback etcd server version to 3.1.11):",
191-
Templates: templates,
192-
}
166+
// Description
167+
prompt = promptx.NewDefaultPrompt(func(line []rune) error {
168+
return nil
169+
}, "Description(eg: Rollback etcd server version to 3.1.11):")
193170

194-
desc, err := prompt.Run()
195-
util.CheckAndExit(err)
171+
desc := prompt.Run()
196172

197173
if strings.TrimSpace(desc) == "big" {
198174
desc = util.OSEditInput()
@@ -202,15 +178,15 @@ func (repo *Repository) XMr() {
202178
desc = lastCommitInfo[1]
203179
}
204180

205-
prompt = promptui.Prompt{
206-
Label: "❯ Target Branch(eg: develop):",
207-
Templates: templates,
208-
Validate: validate,
209-
}
210-
211-
targetBranch, err := prompt.Run()
212-
util.CheckAndExit(err)
181+
// Target Branch
182+
prompt = promptx.NewDefaultPrompt(func(line []rune) error {
183+
if strings.TrimSpace(string(line)) == "" {
184+
return errors.New("Target branch is blank!")
185+
}
186+
return nil
187+
}, "Target Branch(eg: develop)")
213188

189+
targetBranch := prompt.Run()
214190
sourceBranch := util.GetCurrentBranch()
215191

216192
if repo.AutoRebase {

vendor/github.com/chzyer/readline/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

vendor/github.com/chzyer/readline/.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)