Codebase list golang-github-vbauerster-mpb / 7bb14c8
bar filler: prefer meta with explicit string type Vladimir Bauer 2 years ago
1 changed file(s) with 20 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
2323 type BarStyleComposer interface {
2424 BarFillerBuilder
2525 Lbound(string) BarStyleComposer
26 LboundMeta(func(...interface{}) string) BarStyleComposer
26 LboundMeta(func(string) string) BarStyleComposer
2727 Rbound(string) BarStyleComposer
28 RboundMeta(func(...interface{}) string) BarStyleComposer
28 RboundMeta(func(string) string) BarStyleComposer
2929 Filler(string) BarStyleComposer
30 FillerMeta(func(...interface{}) string) BarStyleComposer
30 FillerMeta(func(string) string) BarStyleComposer
3131 Refiller(string) BarStyleComposer
32 RefillerMeta(func(...interface{}) string) BarStyleComposer
32 RefillerMeta(func(string) string) BarStyleComposer
3333 Padding(string) BarStyleComposer
34 PaddingMeta(func(...interface{}) string) BarStyleComposer
34 PaddingMeta(func(string) string) BarStyleComposer
3535 Tip(frames ...string) BarStyleComposer
36 TipMeta(func(...interface{}) string) BarStyleComposer
36 TipMeta(func(string) string) BarStyleComposer
3737 TipOnComplete() BarStyleComposer
3838 Reverse() BarStyleComposer
3939 }
4444 }
4545
4646 type flushSection struct {
47 meta func(io.Writer, ...interface{}) error
47 meta func(io.Writer, []byte) error
4848 bytes []byte
4949 }
5050
5151 type bFiller struct {
5252 components [components]component
53 meta [components]func(io.Writer, ...interface{}) error
53 meta [components]func(io.Writer, []byte) error
5454 flush func(w io.Writer, sections ...flushSection) error
5555 tipOnComplete bool
5656 tip struct {
6161
6262 type barStyle struct {
6363 style [components]string
64 metaFuncs [components]func(io.Writer, ...interface{}) error
64 metaFuncs [components]func(io.Writer, []byte) error
6565 tipFrames []string
6666 tipOnComplete bool
6767 rev bool
8585 return s
8686 }
8787
88 func (s *barStyle) LboundMeta(fn func(...interface{}) string) BarStyleComposer {
88 func (s *barStyle) LboundMeta(fn func(string) string) BarStyleComposer {
8989 s.metaFuncs[iLbound] = makeMetaFunc(fn)
9090 return s
9191 }
9595 return s
9696 }
9797
98 func (s *barStyle) RboundMeta(fn func(...interface{}) string) BarStyleComposer {
98 func (s *barStyle) RboundMeta(fn func(string) string) BarStyleComposer {
9999 s.metaFuncs[iRbound] = makeMetaFunc(fn)
100100 return s
101101 }
105105 return s
106106 }
107107
108 func (s *barStyle) FillerMeta(fn func(...interface{}) string) BarStyleComposer {
108 func (s *barStyle) FillerMeta(fn func(string) string) BarStyleComposer {
109109 s.metaFuncs[iFiller] = makeMetaFunc(fn)
110110 return s
111111 }
115115 return s
116116 }
117117
118 func (s *barStyle) RefillerMeta(fn func(...interface{}) string) BarStyleComposer {
118 func (s *barStyle) RefillerMeta(fn func(string) string) BarStyleComposer {
119119 s.metaFuncs[iRefiller] = makeMetaFunc(fn)
120120 return s
121121 }
125125 return s
126126 }
127127
128 func (s *barStyle) PaddingMeta(fn func(...interface{}) string) BarStyleComposer {
128 func (s *barStyle) PaddingMeta(fn func(string) string) BarStyleComposer {
129129 s.metaFuncs[iPadding] = makeMetaFunc(fn)
130130 return s
131131 }
137137 return s
138138 }
139139
140 func (s *barStyle) TipMeta(fn func(...interface{}) string) BarStyleComposer {
140 func (s *barStyle) TipMeta(fn func(string) string) BarStyleComposer {
141141 s.metaFuncs[iTip] = makeMetaFunc(fn)
142142 return s
143143 }
276276 return s.meta[iRbound](w, s.components[iRbound].bytes)
277277 }
278278
279 func makeMetaFunc(fn func(...interface{}) string) func(io.Writer, ...interface{}) error {
280 return func(w io.Writer, a ...interface{}) (err error) {
281 for i := 0; i < len(a) && err == nil; i++ {
282 _, err = io.WriteString(w, fn(string(a[i].([]byte))))
283 }
279 func makeMetaFunc(fn func(string) string) func(io.Writer, []byte) error {
280 return func(w io.Writer, p []byte) (err error) {
281 _, err = io.WriteString(w, fn(string(p)))
284282 return err
285283 }
286284 }
287285
288 func defaultMeta(w io.Writer, a ...interface{}) (err error) {
289 for i := 0; i < len(a) && err == nil; i++ {
290 _, err = w.Write(a[i].([]byte))
291 }
286 func defaultMeta(w io.Writer, p []byte) (err error) {
287 _, err = w.Write(p)
292288 return err
293289 }