@@ -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
2121const (
22- RCFilename = ".git-czrc"
23- ReservedDefaultName = "default"
22+ RCFilename = ".git-czrc"
23+ ReservedDefaultName = "default"
24+ FieldKeyTemplateSelect = "template-select"
2425)
2526
2627type 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!\n For further configuration visit:\n https://github.com/shipengqi/commitizen" ),
137+ huh .NewSelect [string ]().
138+ Key (FieldKeyTemplateSelect ).
139+ Options (huh .NewOptions (choices ... )... ).
140+ Title (label )),
141+ )
145142}
146143
147144func LoadTemplates (file string ) ([]* render.Template , error ) {
0 commit comments