Codebase list golang-github-vbauerster-mpb / df99206
Refactoring: waitBar to runningBar Vladimir Bauer 8 years ago
4 changed file(s) with 21 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
3232 index int
3333
3434 // pointer to running bar, which this bar should replace
35 waitBar *Bar
35 runningBar *Bar
3636
3737 // completed is set from master Progress goroutine only
3838 completed bool
7676 // following options are assigned to the *Bar
7777 priority int
7878 removeOnComplete bool
79 waitBar *Bar
79 runningBar *Bar
8080 }
8181 refill struct {
8282 char rune
114114 b := &Bar{
115115 priority: s.priority,
116116 removeOnComplete: s.removeOnComplete,
117 waitBar: s.waitBar,
117 runningBar: s.runningBar,
118118 operateState: make(chan func(*bState)),
119119 done: make(chan struct{}),
120120 shutdown: make(chan struct{}),
121121 }
122122
123 if b.waitBar != nil {
124 b.priority = b.waitBar.priority
123 if b.runningBar != nil {
124 b.priority = b.runningBar.priority
125125 }
126126
127127 go b.serve(wg, s, cancel)
8383 }
8484 }
8585
86 // BarPriority sets bar's priority.
87 // Zero is highest priority, i.e. bar will be on top.
88 // If `BarReplaceOnComplete` option is supplied, this option is ignored.
89 func BarPriority(priority int) BarOption {
86 // BarReplaceOnComplete is indicator for delayed bar start, after the `runningBar` is complete.
87 // To achive bar replacement effect, `runningBar` should has its `BarRemoveOnComplete` option set.
88 func BarReplaceOnComplete(runningBar *Bar) BarOption {
9089 return func(s *bState) {
91 s.priority = priority
92 }
93 }
94
95 // BarReplaceOnComplete provided `b` is usually already running bar which this bar should replace.
96 func BarReplaceOnComplete(b *Bar) BarOption {
97 return func(s *bState) {
98 s.waitBar = b
90 s.runningBar = runningBar
9991 }
10092 }
10193
10395 func BarClearOnComplete() BarOption {
10496 return func(s *bState) {
10597 s.noBarOnComplete = true
98 }
99 }
100
101 // BarPriority sets bar's priority.
102 // Zero is highest priority, i.e. bar will be on top.
103 // If `BarReplaceOnComplete` option is supplied, this option is ignored.
104 func BarPriority(priority int) BarOption {
105 return func(s *bState) {
106 s.priority = priority
106107 }
107108 }
108109
118118 // counters unit is multiple by 1000.
119119 // `pairFormat` must contain two printf compatible verbs, like "%f" or "%d".
120120 // First verb substituted with Current, second one with Total.
121 // Example: `"%.1f / %.1f" = "1.0MiB / 12.0MiB"` or `"% .1f / % .1f" = "1.0 MiB / 12.0 MiB"`.
121 // Example: `"%.1f / %.1f" = "1.0MB / 12.0MB"` or `"% .1f / % .1f" = "1.0 MB / 12.0 MB"`.
122122 // If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored.
123123 // `DwidthSync` is effective with multiple bars only, if set decorator will participate
124124 // in width synchronization process with other decorators in the same column group.
9393 case p.operateState <- func(s *pState) {
9494 options = append(options, barWidth(s.width), barFormat(s.format))
9595 b := newBar(p.wg, s.idCounter, total, s.cancel, options...)
96 if b.waitBar != nil {
97 s.waitBars[b.waitBar] = b
96 if b.runningBar != nil {
97 s.waitBars[b.runningBar] = b
9898 } else {
9999 heap.Push(s.bHeap, b)
100100 s.heapUpdated = true