Refactoring: waitBar to runningBar
Vladimir Bauer
8 years ago
| 32 | 32 |
index int
|
| 33 | 33 |
|
| 34 | 34 |
// pointer to running bar, which this bar should replace
|
| 35 | |
waitBar *Bar
|
|
35 |
runningBar *Bar
|
| 36 | 36 |
|
| 37 | 37 |
// completed is set from master Progress goroutine only
|
| 38 | 38 |
completed bool
|
|
| 76 | 76 |
// following options are assigned to the *Bar
|
| 77 | 77 |
priority int
|
| 78 | 78 |
removeOnComplete bool
|
| 79 | |
waitBar *Bar
|
|
79 |
runningBar *Bar
|
| 80 | 80 |
}
|
| 81 | 81 |
refill struct {
|
| 82 | 82 |
char rune
|
|
| 114 | 114 |
b := &Bar{
|
| 115 | 115 |
priority: s.priority,
|
| 116 | 116 |
removeOnComplete: s.removeOnComplete,
|
| 117 | |
waitBar: s.waitBar,
|
|
117 |
runningBar: s.runningBar,
|
| 118 | 118 |
operateState: make(chan func(*bState)),
|
| 119 | 119 |
done: make(chan struct{}),
|
| 120 | 120 |
shutdown: make(chan struct{}),
|
| 121 | 121 |
}
|
| 122 | 122 |
|
| 123 | |
if b.waitBar != nil {
|
| 124 | |
b.priority = b.waitBar.priority
|
|
123 |
if b.runningBar != nil {
|
|
124 |
b.priority = b.runningBar.priority
|
| 125 | 125 |
}
|
| 126 | 126 |
|
| 127 | 127 |
go b.serve(wg, s, cancel)
|
| 83 | 83 |
}
|
| 84 | 84 |
}
|
| 85 | 85 |
|
| 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 {
|
| 90 | 89 |
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
|
| 99 | 91 |
}
|
| 100 | 92 |
}
|
| 101 | 93 |
|
|
| 103 | 95 |
func BarClearOnComplete() BarOption {
|
| 104 | 96 |
return func(s *bState) {
|
| 105 | 97 |
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
|
| 106 | 107 |
}
|
| 107 | 108 |
}
|
| 108 | 109 |
|
| 118 | 118 |
// counters unit is multiple by 1000.
|
| 119 | 119 |
// `pairFormat` must contain two printf compatible verbs, like "%f" or "%d".
|
| 120 | 120 |
// 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"`.
|
| 122 | 122 |
// If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored.
|
| 123 | 123 |
// `DwidthSync` is effective with multiple bars only, if set decorator will participate
|
| 124 | 124 |
// in width synchronization process with other decorators in the same column group.
|
| 93 | 93 |
case p.operateState <- func(s *pState) {
|
| 94 | 94 |
options = append(options, barWidth(s.width), barFormat(s.format))
|
| 95 | 95 |
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
|
| 98 | 98 |
} else {
|
| 99 | 99 |
heap.Push(s.bHeap, b)
|
| 100 | 100 |
s.heapUpdated = true
|