diff --git a/bar.go b/bar.go index ceede03..ee71b0f 100644 --- a/bar.go +++ b/bar.go @@ -406,14 +406,14 @@ columns := make([]chan int, 0, len(s.pDecorators)+len(s.aDecorators)) var pCount int for _, d := range s.pDecorators { - if ok, ch := d.SyncWidth(); ok { + if ok, ch := d.Syncable(); ok { columns = append(columns, ch) pCount++ } } var aCount int for _, d := range s.aDecorators { - if ok, ch := d.SyncWidth(); ok { + if ok, ch := d.Syncable(); ok { columns = append(columns, ch) aCount++ } diff --git a/decor/decorator.go b/decor/decorator.go index 44846bd..0a395ec 100644 --- a/decor/decorator.go +++ b/decor/decorator.go @@ -47,9 +47,17 @@ } // Decorator interface. +// A decorator must implement this interface, in order to be used with mpb library. type Decorator interface { Decor(*Statistics) string - SyncWidth() (bool, chan int) + Syncable +} + +// Syncable interface. +// All decorators implement this interface implicitly. +// Its Syncable method exposes width sync channel, if sync is enabled. +type Syncable interface { + Syncable() (bool, chan int) } // OnCompleteMessenger interface. @@ -58,13 +66,16 @@ OnCompleteMessage(string) } +// AmountReceiver interface. +// If decorator needs to receive increment amount, +// so this is the right interface to implement. type AmountReceiver interface { NextAmount(int, ...time.Duration) } // ShutdownListener interface. -// If decorator implements this interface, its Shutdown method -// will be called once on bar shutdown event. +// If decorator needs to be notified once upon bar shutdown event, +// so this is the right interface to implement. type ShutdownListener interface { Shutdown() } @@ -115,7 +126,7 @@ } } -func (wc *WC) SyncWidth() (bool, chan int) { +func (wc *WC) Syncable() (bool, chan int) { return (wc.C & DSyncWidth) != 0, wc.wsync } @@ -132,6 +143,7 @@ return decorator } +// completeMsg for internal usage. type completeMsg struct { msg string }