Codebase list golang-github-vbauerster-mpb / e45a20b
godocs Vladimir Bauer 7 years ago
5 changed file(s) with 27 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
3333 }
3434
3535 // Filler interface.
36 // Bar renders 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.
36 // Bar renders by calling Filler's Fill method. You can literally have
37 // any bar kind, by implementing this interface and passing it to the
38 // Add method.
3939 type Filler interface {
4040 Fill(w io.Writer, width int, s *decor.Statistics)
4141 }
217217 }
218218
219219 // IncrBy increments progress bar by amount of n.
220 // wdd is optional work duration i.e. time.Since(start),
221 // which expected to be provided, if any ewma based decorator is used.
220 // wdd is optional work duration i.e. time.Since(start), which expected
221 // to be provided, if any ewma based decorator is used.
222222 func (b *Bar) IncrBy(n int, wdd ...time.Duration) {
223223 select {
224224 case b.operateState <- func(s *bState) {
238238 // Completed reports whether the bar is in completed state.
239239 func (b *Bar) Completed() bool {
240240 // omit select here, because primary usage of the method is for loop
241 // condition, like for !bar.Completed() {...}
242 // so when toComplete=true it is called once (at which time, the bar is still alive),
243 // then quits the loop and never suppose to be called afterwards.
241 // condition, like for !bar.Completed() {...} so when toComplete=true
242 // it is called once (at which time, the bar is still alive), then
243 // quits the loop and never suppose to be called afterwards.
244244 return <-b.boolCh
245245 }
246246
66 )
77
88 // MovingAverage is the interface that computes a moving average over
9 // a time- series stream of numbers. The average may be over a window
9 // a time-series stream of numbers. The average may be over a window
1010 // or exponentially decaying.
1111 type MovingAverage interface {
1212 Add(float64)
1212 // behavior of progress pool, if passed to mpb.New(...ProgressOption).
1313 type ProgressOption func(*pState)
1414
15 // WithWaitGroup provides means to have a single joint point. If
15 // WithWaitGroup provides means to have a single joint point. If
1616 // *sync.WaitGroup is provided, you can safely call just p.Wait()
17 // without calling Wait() on provided *sync.WaitGroup. Makes sense
17 // without calling Wait() on provided *sync.WaitGroup. Makes sense
1818 // when there are more than one bar to render.
1919 func WithWaitGroup(wg *sync.WaitGroup) ProgressOption {
2020 return func(s *pState) {
2222 }
2323 }
2424
25 // WithWidth overrides default width 80.
25 // WithWidth sets container width. Default is 80. Bars inherit this
26 // width, as long as no BarWidth is applied.
2627 func WithWidth(w int) ProgressOption {
2728 return func(s *pState) {
2829 if w >= 0 {
4949 debugOut io.Writer
5050 }
5151
52 // New creates new Progress instance, which orchestrates bars rendering process.
53 // Accepts mpb.ProgressOption funcs for customization.
52 // New creates new Progress instance, which orchestrates bars rendering
53 // process. Accepts mpb.ProgressOption funcs for customization.
5454 func New(options ...ProgressOption) *Progress {
5555 pq := make(priorityQueue, 0)
5656 heap.Init(&pq)
119119 }
120120 }
121121
122 // Abort is only effective while bar progress is running,
123 // it means remove bar now without waiting for its completion.
124 // If bar is already completed, there is nothing to abort.
125 // If you need to remove bar after completion, use BarRemoveOnComplete BarOption.
122 // Abort is only effective while bar progress is running, it means
123 // remove bar now without waiting for its completion. If bar is already
124 // completed, there is nothing to abort. If you need to remove bar
125 // after completion, use BarRemoveOnComplete BarOption.
126126 func (p *Progress) Abort(b *Bar, remove bool) {
127127 select {
128128 case p.operateState <- func(s *pState) {
158158 }
159159 }
160160
161 // Wait first waits for user provided *sync.WaitGroup, if any,
162 // then waits far all bars to complete and finally shutdowns master goroutine.
163 // After this method has been called, there is no way to reuse *Progress instance.
161 // Wait first waits for user provided *sync.WaitGroup, if any, then
162 // waits far all bars to complete and finally shutdowns master goroutine.
163 // After this method has been called, there is no way to reuse *Progress
164 // instance.
164165 func (p *Progress) Wait() {
165166 if p.uwg != nil {
166167 p.uwg.Wait()
218219 defer func() {
219220 if frameReader.toShutdown {
220221 // shutdown at next flush, in other words decrement underlying WaitGroup
221 // only after the bar with completed state has been flushed.
222 // this ensures no bar ends up with less than 100% rendered.
222 // only after the bar with completed state has been flushed. this
223 // ensures no bar ends up with less than 100% rendered.
223224 s.shutdownPending = append(s.shutdownPending, bar)
224225 if replacementBar, ok := s.waitBars[bar]; ok {
225226 heap.Push(s.bHeap, replacementBar)
77 "github.com/vbauerster/mpb/decor"
88 )
99
10 // SpinnerAlignment erum.
1011 type SpinnerAlignment int
1112
13 // SpinnerAlignment kinds.
1214 const (
1315 SpinnerOnLeft SpinnerAlignment = iota
1416 SpinnerOnMiddle