Skip to content

Commit f354086

Browse files
authored
Merge pull request #59 from shipengqi/feat/hub
feat(ui): ui improvement
2 parents da2ab35 + ffd4c32 commit f354086

File tree

21 files changed

+131
-789
lines changed

21 files changed

+131
-789
lines changed

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ jobs:
6161
key: commitizen-${{ github.event.pull_request.number }}-${{ github.sha }}
6262
- name: Run E2E test
6363
run: |
64-
GOPATH=~/go make e2e NO_TTY=1
64+
GOPATH=~/go make e2e

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ Options:
2424
This option is available when using: make release
2525
V Set to 1 enable verbose build. Default is 0.
2626
DEBUG Whether to generate debug symbols. Default is 0.
27-
NO_TTY Make sure that the TTY (terminal) is never used for
28-
any output. Default is 0.
2927
endef
3028
export USAGE_OPTIONS
3129

cmd/cz/cz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func New() *cobra.Command {
3434
return err
3535
}
3636

37-
msg, err := tmpl.Run(o.NoTTY)
37+
msg, err := tmpl.Run()
3838
if err != nil {
3939
return err
4040
}

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module github.com/shipengqi/commitizen
33
go 1.22
44

55
require (
6-
github.com/charmbracelet/bubbles v0.18.0
7-
github.com/charmbracelet/bubbletea v0.25.0
8-
github.com/charmbracelet/lipgloss v0.10.0
6+
github.com/charmbracelet/huh v0.3.0
97
github.com/onsi/ginkgo/v2 v2.17.1
108
github.com/onsi/gomega v1.33.0
119
github.com/shipengqi/component-base v0.2.9
@@ -19,6 +17,10 @@ require (
1917
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
2018
github.com/atotto/clipboard v0.1.4 // indirect
2119
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
20+
github.com/catppuccin/go v0.2.0 // indirect
21+
github.com/charmbracelet/bubbles v0.18.0 // indirect
22+
github.com/charmbracelet/bubbletea v0.25.0 // indirect
23+
github.com/charmbracelet/lipgloss v0.10.0 // indirect
2224
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
2325
github.com/fatih/color v1.16.0 // indirect
2426
github.com/go-logr/logr v1.4.1 // indirect
@@ -34,12 +36,11 @@ require (
3436
github.com/mattn/go-localereader v0.0.1 // indirect
3537
github.com/mattn/go-runewidth v0.0.15 // indirect
3638
github.com/moby/term v0.5.0 // indirect
37-
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
39+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
3840
github.com/muesli/cancelreader v0.2.2 // indirect
3941
github.com/muesli/reflow v0.3.0 // indirect
4042
github.com/muesli/termenv v0.15.2 // indirect
4143
github.com/rivo/uniseg v0.4.7 // indirect
42-
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
4344
golang.org/x/net v0.23.0 // indirect
4445
golang.org/x/sync v0.6.0 // indirect
4546
golang.org/x/sys v0.19.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
44
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
55
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
66
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
7+
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
8+
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
79
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
810
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
911
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
1012
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
13+
github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
14+
github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
1115
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
1216
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
1317
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
@@ -41,8 +45,6 @@ github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
4145
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
4246
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4347
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
44-
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
45-
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
4648
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
4749
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
4850
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@@ -57,8 +59,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
5759
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
5860
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
5961
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
60-
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
61-
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
62+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
63+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
6264
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
6365
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
6466
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
@@ -76,8 +78,6 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
7678
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
7779
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
7880
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
79-
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
80-
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
8181
github.com/shipengqi/component-base v0.2.9 h1:4XRB6PzTRgqKkkxkJwnpK8YOqDHRzXviyyis67YBhgE=
8282
github.com/shipengqi/component-base v0.2.9/go.mod h1:LfbMJtgUW7nNPwmVIi5wJMif/066edkcIJtkDDJgEQQ=
8383
github.com/shipengqi/golib v0.2.12 h1:/0hrev7+J8KChxEvoVdS2kbGQT8VO4C4qFAhtn6ZI8o=

hack/include/test.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
GINKGO := $(shell go env GOPATH)/bin/ginkgo
1616
CLI ?= $(OUTPUT_DIR)/commitizen
17-
NO_TTY ?= 0
1817

1918
.PHONY: test.cover
2019
test.cover:
@@ -25,4 +24,4 @@ test.cover:
2524
.PHONY: test.e2e
2625
test.e2e: tools.verify.ginkgo
2726
@echo "===========> Run e2e test, CLI: $(CLI)"
28-
@$(GINKGO) -v $(REPO_ROOT)/test/e2e -- -cli=$(CLI) -no-tty=$(NO_TTY)
27+
@$(GINKGO) -v $(REPO_ROOT)/test/e2e -- -cli=$(CLI)

internal/config/config.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import (
88
"os"
99
"path/filepath"
1010

11+
"github.com/charmbracelet/huh"
1112
"github.com/shipengqi/golib/convutil"
1213
"github.com/shipengqi/golib/fsutil"
1314
"github.com/shipengqi/golib/sysutil"
1415
"gopkg.in/yaml.v3"
1516

1617
"github.com/shipengqi/commitizen/internal/options"
1718
"github.com/shipengqi/commitizen/internal/render"
18-
"github.com/shipengqi/commitizen/internal/ui"
1919
)
2020

2121
const (
22-
RCFilename = ".git-czrc"
23-
ReservedDefaultName = "default"
22+
RCFilename = ".git-czrc"
23+
ReservedDefaultName = "default"
24+
FieldKeyTemplateSelect = "template-select"
2425
)
2526

2627
type Config struct {
@@ -59,7 +60,7 @@ func (c *Config) initialize() error {
5960
continue
6061
}
6162
if v.Name == ReservedDefaultName {
62-
return errors.New("template name 'default' is reserved, use 'default' as the template name, default must be true")
63+
return errors.New("template name 'default' is reserved, to override the default template, you need to set default to true")
6364
}
6465
if _, ok := exists[v.Name]; ok {
6566
return fmt.Errorf("duplicate template '%s'", v.Name)
@@ -103,14 +104,12 @@ func (c *Config) Run(opts *options.Options) (*render.Template, error) {
103104
}
104105

105106
if len(c.more) > 0 {
106-
model := c.createTemplatesSelect("Select a template to use for this commit:")
107-
if _, err = ui.Run(model, opts.NoTTY); err != nil {
107+
form := c.createTemplatesSelect("Select the template of change that you're committing:")
108+
if err = form.Run(); err != nil {
108109
return nil, err
109110
}
110-
if model.Canceled() {
111-
return nil, render.ErrCanceled
112-
}
113-
val := model.Value()
111+
112+
val := form.GetString(FieldKeyTemplateSelect)
114113
if val == c.defaultTmpl.Name {
115114
return c.defaultTmpl, nil
116115
}
@@ -123,25 +122,23 @@ func (c *Config) Run(opts *options.Options) (*render.Template, error) {
123122
return c.defaultTmpl, nil
124123
}
125124

126-
func (c *Config) createTemplatesSelect(label string) *ui.SelectModel {
127-
var choices ui.Choices
125+
func (c *Config) createTemplatesSelect(label string) *huh.Form {
126+
var choices []string
128127
var all []*render.Template
129128
all = append(all, c.more...)
130129
all = append(all, c.defaultTmpl)
131130
// list custom templates and default templates
132131
for _, v := range all {
133-
choices = append(choices, ui.Choice(v.Name))
132+
choices = append(choices, v.Name)
134133
}
135-
height := 8
136-
if len(all) > 5 {
137-
height = 12
138-
} else if len(all) > 3 {
139-
height = 10
140-
} else if len(all) > 2 {
141-
height = 9
142-
}
143-
m := ui.NewSelect(label, choices).WithHeight(height)
144-
return m
134+
135+
return huh.NewForm(huh.NewGroup(
136+
huh.NewNote().Title("Commitizen").Description("Welcome to Commitizen!\nFor further configuration visit:\nhttps://github.com/shipengqi/commitizen"),
137+
huh.NewSelect[string]().
138+
Key(FieldKeyTemplateSelect).
139+
Options(huh.NewOptions(choices...)...).
140+
Title(label)),
141+
)
145142
}
146143

147144
func LoadTemplates(file string) ([]*render.Template, error) {

internal/options/options.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
type Options struct {
1010
DryRun bool
11-
NoTTY bool
1211
Default bool
1312
Template string
1413
GitOptions *git.Options
@@ -28,9 +27,6 @@ func (o *Options) Flags() (fss cliflag.NamedFlagSets) {
2827
fs.BoolVar(&o.DryRun, "dry-run", o.DryRun, "do not create a commit, but show the message and list of paths \nthat are to be committed.")
2928
fs.StringVarP(&o.Template, "template", "t", o.Template, "template name to use when multiple templates exist.")
3029
fs.BoolVarP(&o.Default, "default", "d", o.Default, "use the default template, '--default' has a higher priority than '--template'.")
31-
fs.BoolVar(&o.NoTTY, "no-tty", o.NoTTY, "make sure that the TTY (terminal) is never used for any output.")
32-
33-
_ = fs.MarkHidden("no-tty")
3430

3531
return
3632
}

internal/render/errors.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package render
22

33
import (
4-
"errors"
54
"fmt"
65
)
76

8-
var (
9-
ErrCanceled = errors.New("canceled")
10-
)
11-
127
type MissingErr struct {
138
field string
149
}

0 commit comments

Comments
 (0)