BarPriority option
Vladimir Bauer
8 years ago
| 58 | 58 |
trimLeftSpace bool
|
| 59 | 59 |
trimRightSpace bool
|
| 60 | 60 |
toComplete bool
|
| 61 | |
removeOnComplete bool
|
| 62 | 61 |
dynamic bool
|
| 63 | 62 |
startTime time.Time
|
| 64 | 63 |
timeElapsed time.Duration
|
|
| 69 | 68 |
refill *refill
|
| 70 | 69 |
bufP, bufB, bufA *bytes.Buffer
|
| 71 | 70 |
panicMsg string
|
|
71 |
|
|
72 |
// following options are assigned to the *Bar
|
|
73 |
priority int
|
|
74 |
removeOnComplete bool
|
| 72 | 75 |
}
|
| 73 | 76 |
refill struct {
|
| 74 | 77 |
char rune
|
|
| 88 | 91 |
|
| 89 | 92 |
s := &bState{
|
| 90 | 93 |
id: id,
|
|
94 |
priority: id,
|
| 91 | 95 |
total: total,
|
| 92 | 96 |
etaAlpha: etaAlpha,
|
| 93 | 97 |
}
|
|
| 103 | 107 |
s.bufA = bytes.NewBuffer(make([]byte, 0, s.width))
|
| 104 | 108 |
|
| 105 | 109 |
b := &Bar{
|
| 106 | |
priority: id,
|
|
110 |
priority: s.priority,
|
| 107 | 111 |
removeOnComplete: s.removeOnComplete,
|
| 108 | 112 |
operateState: make(chan func(*bState)),
|
| 109 | 113 |
done: make(chan struct{}),
|
| 81 | 81 |
}
|
| 82 | 82 |
}
|
| 83 | 83 |
|
|
84 |
// BarPriority sets bar's priority.
|
|
85 |
// Zero is highest priority, i.e. bar will be on top.
|
|
86 |
func BarPriority(priority int) BarOption {
|
|
87 |
return func(s *bState) {
|
|
88 |
s.priority = priority
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
| 84 | 92 |
func barWidth(w int) BarOption {
|
| 85 | 93 |
return func(s *bState) {
|
| 86 | 94 |
s.width = w
|
| 1 | 1 |
|
| 2 | 2 |
import "container/heap"
|
| 3 | 3 |
|
| 4 | |
// A priorityQueue implements heap.Interface and holds Items.
|
|
4 |
// A priorityQueue implements heap.Interface
|
| 5 | 5 |
type priorityQueue []*Bar
|
| 6 | 6 |
|
| 7 | 7 |
func (pq priorityQueue) Len() int { return len(pq) }
|
|
| 32 | 32 |
return bar
|
| 33 | 33 |
}
|
| 34 | 34 |
|
| 35 | |
// update modifies the priority of an Bar in the queue.
|
|
35 |
// update modifies the priority of a Bar in the queue.
|
| 36 | 36 |
func (pq *priorityQueue) update(bar *Bar, priority int) {
|
| 37 | 37 |
bar.priority = priority
|
| 38 | 38 |
heap.Fix(pq, bar.index)
|