fmt godocs
Vladimir Bauer
7 years ago
| 32 | 32 | shutdown chan struct{} |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | // Filler interface. | |
| 36 | // Bar rednders by calling Filler's Fill method. You can literally | |
| 37 | // have any bar kind, by implementing this interface and passing it | |
| 38 | // to the Add method. | |
| 35 | 39 | type Filler interface { |
| 36 | 40 | Fill(w io.Writer, width int, s *decor.Statistics) |
| 37 | 41 | } |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | // BarRemoveOnComplete is a flag, if set whole bar line will be removed on complete event. | |
| 50 | // If both BarRemoveOnComplete and BarClearOnComplete are set, first bar section gets cleared | |
| 51 | // and then whole bar line gets removed completely. | |
| 49 | // BarRemoveOnComplete is a flag, if set whole bar line will be removed | |
| 50 | // on complete event. If both BarRemoveOnComplete and BarClearOnComplete | |
| 51 | // are set, first bar section gets cleared and then whole bar line | |
| 52 | // gets removed completely. | |
| 52 | 53 | func BarRemoveOnComplete() BarOption { |
| 53 | 54 | return func(s *bState) { |
| 54 | 55 | s.removeOnComplete = true |
| 55 | 56 | } |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | // BarReplaceOnComplete is indicator for delayed bar start, after the `runningBar` is complete. | |
| 59 | // To achieve bar replacement effect, `runningBar` should has its `BarRemoveOnComplete` option set. | |
| 59 | // BarReplaceOnComplete is indicator for delayed bar start, after the | |
| 60 | // `runningBar` is complete. To achieve bar replacement effect, | |
| 61 | // `runningBar` should has its `BarRemoveOnComplete` option set. | |
| 60 | 62 | func BarReplaceOnComplete(runningBar *Bar) BarOption { |
| 61 | 63 | return func(s *bState) { |
| 62 | 64 | s.runningBar = runningBar |
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | // BarClearOnComplete is a flag, if set will clear bar section on complete event. | |
| 67 | // If you need to remove a whole bar line, refer to BarRemoveOnComplete. | |
| 68 | // BarClearOnComplete is a flag, if set will clear bar section on | |
| 69 | // complete event. If you need to remove a whole bar line, refer to | |
| 70 | // BarRemoveOnComplete. | |
| 68 | 71 | func BarClearOnComplete() BarOption { |
| 69 | 72 | return func(s *bState) { |
| 70 | 73 | s.barClearOnComplete = true |
| 72 | 75 | } |
| 73 | 76 | |
| 74 | 77 | // BarPriority sets bar's priority. |
| 75 | // Zero is highest priority, i.e. bar will be on top. | |
| 76 | // If `BarReplaceOnComplete` option is supplied, this option is ignored. | |
| 78 | // Zero is highest priority, i.e. bar will be on top. If | |
| 79 | // `BarReplaceOnComplete` option is supplied, this option is ignored. | |
| 77 | 80 | func BarPriority(priority int) BarOption { |
| 78 | 81 | return func(s *bState) { |
| 79 | 82 | s.priority = priority |
| 80 | 83 | } |
| 81 | 84 | } |
| 82 | 85 | |
| 83 | // BarNewLineExtend takes user defined efn, which gets called each render cycle. | |
| 84 | // Any write to provided writer of efn, will appear on new line of respective bar. | |
| 86 | // BarNewLineExtend takes user defined efn, which gets called each | |
| 87 | // render cycle. Any write to provided writer of efn, will appear on | |
| 88 | // new line of respective bar. | |
| 85 | 89 | func BarNewLineExtend(efn func(io.Writer, *decor.Statistics)) BarOption { |
| 86 | 90 | return func(s *bState) { |
| 87 | 91 | s.newLineExtendFn = efn |
| 135 | 139 | return MakeFillerTypeSpecificBarOption(chk, cb) |
| 136 | 140 | } |
| 137 | 141 | |
| 138 | // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's actual type. | |
| 139 | // If you implement your own Filler, so most probably you'll need this. | |
| 140 | // See BarStyle or SpinnerStyle for example. | |
| 142 | // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's | |
| 143 | // actual type. If you implement your own Filler, so most probably | |
| 144 | // you'll need this. See BarStyle or SpinnerStyle for example. | |
| 141 | 145 | func MakeFillerTypeSpecificBarOption( |
| 142 | 146 | typeChecker func(Filler) (interface{}, bool), |
| 143 | 147 | cb func(interface{}), |
| 140 | 140 | return Counters(0, pairFormat, wcc...) |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | // CountersKibiByte is a wrapper around Counters with predefined unit UnitKiB (bytes/1024). | |
| 143 | // CountersKibiByte is a wrapper around Counters with predefined unit | |
| 144 | // UnitKiB (bytes/1024). | |
| 144 | 145 | func CountersKibiByte(pairFormat string, wcc ...WC) Decorator { |
| 145 | 146 | return Counters(UnitKiB, pairFormat, wcc...) |
| 146 | 147 | } |
| 147 | 148 | |
| 148 | // CountersKiloByte is a wrapper around Counters with predefined unit UnitKB (bytes/1000). | |
| 149 | // CountersKiloByte is a wrapper around Counters with predefined unit | |
| 150 | // UnitKB (bytes/1000). | |
| 149 | 151 | func CountersKiloByte(pairFormat string, wcc ...WC) Decorator { |
| 150 | 152 | return Counters(UnitKB, pairFormat, wcc...) |
| 151 | 153 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // Decorator interface. |
| 49 | // A decorator must implement this interface, in order to be used with mpb library. | |
| 49 | // A decorator must implement this interface, in order to be used with | |
| 50 | // mpb library. | |
| 50 | 51 | type Decorator interface { |
| 51 | 52 | Decor(*Statistics) string |
| 52 | 53 | Syncable |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | // Syncable interface. |
| 56 | // All decorators implement this interface implicitly. | |
| 57 | // Its Syncable method exposes width sync channel, if sync is enabled. | |
| 57 | // All decorators implement this interface implicitly. Its Syncable | |
| 58 | // method exposes width sync channel, if sync is enabled. | |
| 58 | 59 | type Syncable interface { |
| 59 | 60 | Syncable() (bool, chan int) |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | // OnCompleteMessenger interface. |
| 63 | // Decorators implementing this interface suppose to return provided string on complete event. | |
| 64 | // Decorators implementing this interface suppose to return provided | |
| 65 | // string on complete event. | |
| 64 | 66 | type OnCompleteMessenger interface { |
| 65 | 67 | OnCompleteMessage(string) |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | // AmountReceiver interface. |
| 69 | // If decorator needs to receive increment amount, | |
| 70 | // so this is the right interface to implement. | |
| 71 | // If decorator needs to receive increment amount, so this is the right | |
| 72 | // interface to implement. | |
| 71 | 73 | type AmountReceiver interface { |
| 72 | 74 | NextAmount(int, ...time.Duration) |
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | // ShutdownListener interface. |
| 76 | // If decorator needs to be notified once upon bar shutdown event, | |
| 77 | // so this is the right interface to implement. | |
| 78 | // If decorator needs to be notified once upon bar shutdown event, so | |
| 79 | // this is the right interface to implement. | |
| 78 | 80 | type ShutdownListener interface { |
| 79 | 81 | Shutdown() |
| 80 | 82 | } |
| 129 | 131 | return (wc.C & DSyncWidth) != 0, wc.wsync |
| 130 | 132 | } |
| 131 | 133 | |
| 132 | // OnComplete returns decorator, which wraps provided decorator, with sole | |
| 133 | // purpose to display provided message on complete event. | |
| 134 | // OnComplete returns decorator, which wraps provided decorator, with | |
| 135 | // sole purpose to display provided message on complete event. | |
| 134 | 136 | // |
| 135 | 137 | // `decorator` Decorator to wrap |
| 136 | 138 | // |
| 5 | 5 | "github.com/VividCortex/ewma" |
| 6 | 6 | ) |
| 7 | 7 | |
| 8 | // MovingAverage is the interface that computes a moving average over a time- | |
| 9 | // series stream of numbers. The average may be over a window or exponentially | |
| 10 | // decaying. | |
| 8 | // MovingAverage is the interface that computes a moving average over | |
| 9 | // a time- series stream of numbers. The average may be over a window | |
| 10 | // or exponentially decaying. | |
| 11 | 11 | type MovingAverage interface { |
| 12 | 12 | Add(float64) |
| 13 | 13 | Value() float64 |
| 56 | 56 | s.count++ |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | // NewMedianEwma is ewma based MovingAverage, which gets its values from median MovingAverage. | |
| 59 | // NewMedianEwma is ewma based MovingAverage, which gets its values | |
| 60 | // from median MovingAverage. | |
| 60 | 61 | func NewMedianEwma(age ...float64) MovingAverage { |
| 61 | 62 | return &medianEwma{ |
| 62 | 63 | MovingAverage: ewma.NewMovingAverage(age...), |
| 136 | 136 | return MovingAverageSpeed(unit, unitFormat, ewma.NewMovingAverage(age), wcc...) |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | // MovingAverageSpeed decorator relies on MovingAverage implementation to calculate its average. | |
| 139 | // MovingAverageSpeed decorator relies on MovingAverage implementation | |
| 140 | // to calculate its average. | |
| 140 | 141 | // |
| 141 | 142 | // `unit` one of [0|UnitKiB|UnitKB] zero for no unit |
| 142 | 143 | // |
| 8 | 8 | "github.com/vbauerster/mpb/cwriter" |
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | // ProgressOption is a function option which changes the default behavior of | |
| 12 | // progress pool, if passed to mpb.New(...ProgressOption). | |
| 11 | // ProgressOption is a function option which changes the default | |
| 12 | // behavior of progress pool, if passed to mpb.New(...ProgressOption). | |
| 13 | 13 | type ProgressOption func(*pState) |
| 14 | 14 | |
| 15 | // WithWaitGroup provides means to have a single joint point. | |
| 16 | // If *sync.WaitGroup is provided, you can safely call just p.Wait() | |
| 17 | // without calling Wait() on provided *sync.WaitGroup. | |
| 18 | // Makes sense when there are more than one bar to render. | |
| 15 | // WithWaitGroup provides means to have a single joint point. If | |
| 16 | // *sync.WaitGroup is provided, you can safely call just p.Wait() | |
| 17 | // without calling Wait() on provided *sync.WaitGroup. Makes sense | |
| 18 | // when there are more than one bar to render. | |
| 19 | 19 | func WithWaitGroup(wg *sync.WaitGroup) ProgressOption { |
| 20 | 20 | return func(s *pState) { |
| 21 | 21 | s.uwg = wg |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | // WithShutdownNotifier provided chanel will be closed, after all bars have been rendered. | |
| 62 | // WithShutdownNotifier provided chanel will be closed, after all bars | |
| 63 | // have been rendered. | |
| 63 | 64 | func WithShutdownNotifier(ch chan struct{}) ProgressOption { |
| 64 | 65 | return func(s *pState) { |
| 65 | 66 | s.shutdownNotifier = ch |