refactoring Any
no need for pointer receiver
Vladimir Bauer
2 years ago
| 0 | 0 | package decor |
| 1 | 1 | |
| 2 | var _ Decorator = (*any)(nil) | |
| 2 | var _ Decorator = any{} | |
| 3 | 3 | |
| 4 | // Any decorator displays text, that can be changed during decorator's | |
| 5 | // lifetime via provided DecorFunc. | |
| 4 | // Any decorator. | |
| 5 | // Converts DecorFunc into Decorator. | |
| 6 | 6 | // |
| 7 | 7 | // `fn` DecorFunc callback |
| 8 | // | |
| 9 | 8 | // `wcc` optional WC config |
| 10 | 9 | func Any(fn DecorFunc, wcc ...WC) Decorator { |
| 11 | return &any{initWC(wcc...), fn} | |
| 10 | return any{initWC(wcc...), fn} | |
| 12 | 11 | } |
| 13 | 12 | |
| 14 | 13 | type any struct { |
| 16 | 15 | fn DecorFunc |
| 17 | 16 | } |
| 18 | 17 | |
| 19 | func (d *any) Decor(s Statistics) string { | |
| 20 | return d.FormatMsg(d.fn(s)) | |
| 18 | func (d any) Decor(s Statistics) (string, int) { | |
| 19 | return d.Format(d.fn(s)) | |
| 21 | 20 | } |