Codebase list golang-github-vbauerster-mpb / e24a54e
Any decorator Vladimir Bauer 6 years ago
2 changed file(s) with 29 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 package decor
1
2 // Any decorator displays text, that can be changed during decorator's
3 // lifetime via provided func call back.
4 //
5 // `f` call back which provides string to display
6 //
7 // `wcc` optional WC config
8 //
9 func Any(f func(*Statistics) string, wcc ...WC) Decorator {
10 return &any{initWC(wcc...), f}
11 }
12
13 type any struct {
14 WC
15 f func(*Statistics) string
16 }
17
18 func (d *any) Decor(s *Statistics) string {
19 return d.FormatMsg(d.f(s))
20 }
175175 func (wc *WC) SetConf(conf WC) {
176176 *wc = conf.Init()
177177 }
178
179 func initWC(wcc ...WC) WC {
180 var wc WC
181 for _, nwc := range wcc {
182 wc = nwc
183 }
184 return wc.Init()
185 }