diff --git a/_examples/suppressBar/main.go b/_examples/suppressBar/main.go index 416f3e4..6f68a37 100644 --- a/_examples/suppressBar/main.go +++ b/_examples/suppressBar/main.go @@ -101,15 +101,23 @@ ew.Unlock() } +type percentage struct { + decor.Decorator + suspend <-chan struct{} +} + +func (d percentage) Decor(s decor.Statistics) (string, int) { + select { + case <-d.suspend: + return d.Format("") + default: + return d.Decorator.Decor(s) + } +} + func newCustomPercentage(nextCh <-chan struct{}) decor.Decorator { - base := decor.Percentage() - fn := func(s decor.Statistics) string { - select { - case <-nextCh: - return "" - default: - return base.Decor(s) - } + return percentage{ + Decorator: decor.Percentage(), + suspend: nextCh, } - return decor.Any(fn) }