@@ -2,7 +2,6 @@ package render
22
33import (
44 "bytes"
5- "errors"
65 "fmt"
76 "strings"
87 "text/template"
@@ -74,7 +73,7 @@ func (t *Template) Run() ([]byte, error) {
7473 return nil , err
7574 }
7675 if v .model .Canceled () {
77- return nil , errors . New ( "canceled" )
76+ return nil , ErrCanceled
7877 }
7978 val := v .model .Value ()
8079 // hardcode for the select options
@@ -102,18 +101,18 @@ func (t *Template) Run() ([]byte, error) {
102101
103102func (t * Template ) init () error {
104103 if isEmptyStr (t .Format ) {
105- return errors . New ("format is required " )
104+ return NewMissingErr ("format" )
106105 }
107106
108107 for _ , item := range t .Items {
109108 if isEmptyStr (item .Name ) {
110- return errors . New ("item.name is required " )
109+ return NewMissingErr ("item.name" )
111110 }
112111 if isEmptyStr (item .Desc ) {
113- return errors . New ("item.desc is required " )
112+ return NewMissingErr ("item.desc" )
114113 }
115114 if isEmptyStr (item .Type ) {
116- return errors . New ("item.type is required " )
115+ return NewMissingErr ("item.type" )
117116 }
118117
119118 var m ui.Model
@@ -147,7 +146,7 @@ func (t *Template) createSelectItem(label string, options []Option) *ui.SelectMo
147146}
148147
149148func (t * Template ) createInputItem (name , label string , required bool ) * ui.InputModel {
150- m := ui .NewInput (label )
149+ m := ui .NewInput (label ). WithWidth ( 30 )
151150 if required {
152151 m .WithValidateFunc (NotBlankValidator (name ))
153152 }
@@ -166,7 +165,7 @@ func (t *Template) createTextAreaItem(name, label string, required bool) *ui.Tex
166165func NotBlankValidator (name string ) func (s string ) error {
167166 return func (s string ) error {
168167 if strings .TrimSpace (s ) == "" {
169- return fmt . Errorf ( "%s is required" , name )
168+ return NewMissingErr ( name )
170169 }
171170 return nil
172171 }
0 commit comments