diff --git a/decor/any.go b/decor/any.go new file mode 100644 index 0000000..bf9cf51 --- /dev/null +++ b/decor/any.go @@ -0,0 +1,21 @@ +package decor + +// Any decorator displays text, that can be changed during decorator's +// lifetime via provided func call back. +// +// `f` call back which provides string to display +// +// `wcc` optional WC config +// +func Any(f func(*Statistics) string, wcc ...WC) Decorator { + return &any{initWC(wcc...), f} +} + +type any struct { + WC + f func(*Statistics) string +} + +func (d *any) Decor(s *Statistics) string { + return d.FormatMsg(d.f(s)) +} diff --git a/decor/decorator.go b/decor/decorator.go index 2271cbb..01b6780 100644 --- a/decor/decorator.go +++ b/decor/decorator.go @@ -176,3 +176,11 @@ func (wc *WC) SetConf(conf WC) { *wc = conf.Init() } + +func initWC(wcc ...WC) WC { + var wc WC + for _, nwc := range wcc { + wc = nwc + } + return wc.Init() +}