Codebase list golang-github-vbauerster-mpb / 424eb1a
ignore complete by means of SetTotal(int64, bool) should fix #48 and #63 Vladimir Bauer 6 years ago
3 changed file(s) with 14 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
6868 trimSpace bool
6969 toComplete bool
7070 completeFlushed bool
71 ignoreComplete bool
7172 noPop bool
7273 aDecorators []decor.Decorator
7374 pDecorators []decor.Decorator
169170 }
170171
171172 // SetTotal sets total dynamically.
172 // If total is less or equal to zero it takes progress' current value.
173 // If complete is true, complete event will be triggered.
173 // If total is less than or equal to zero it takes progress' current value.
174 // A complete flag enables or disables complete event on `current >= total`.
174175 func (b *Bar) SetTotal(total int64, complete bool) {
175176 select {
176177 case b.operateState <- func(s *bState) {
178 s.ignoreComplete = !complete
177179 if total <= 0 {
178180 s.total = s.current
179181 } else {
180182 s.total = total
181183 }
182 if complete && !s.toComplete {
184 if !s.ignoreComplete && !s.toComplete {
183185 s.current = s.total
184186 s.toComplete = true
185187 go b.refreshTillShutdown()
196198 s.iterated = true
197199 s.lastN = current - s.current
198200 s.current = current
199 if s.total > 0 && s.current >= s.total {
201 if !s.ignoreComplete && s.current >= s.total {
200202 s.current = s.total
201203 s.toComplete = true
202204 go b.refreshTillShutdown()
223225 s.iterated = true
224226 s.lastN = n
225227 s.current += n
226 if s.total > 0 && s.current >= s.total {
228 if !s.ignoreComplete && s.current >= s.total {
227229 s.current = s.total
228230 s.toComplete = true
229231 go b.refreshTillShutdown()
66 if total <= 0 {
77 return 0
88 }
9 if current >= total {
10 return float64(width)
11 }
912 return float64(int64(width)*current) / float64(total)
1013 }
1114
2020 {"t,c,e{100,50,50}", 100, 50, 50},
2121 {"t,c,e{100,99,99}", 100, 99, 99},
2222 {"t,c,e{100,100,100}", 100, 100, 100},
23 {"t,c,e{100,101,101}", 100, 101, 101},
24 {"t,c,e{100,102,101}", 100, 102, 102},
23 {"t,c,e{100,101,101}", 100, 101, 100},
2524 {"t,c,e{120,0,0}", 120, 0, 0},
2625 {"t,c,e{120,10,8}", 120, 10, 8},
2726 {"t,c,e{120,15,13}", 120, 15, 13},
3231 {"t,c,e{120,118,98}", 120, 118, 98},
3332 {"t,c,e{120,119,99}", 120, 119, 99},
3433 {"t,c,e{120,120,100}", 120, 120, 100},
35 {"t,c,e{120,121,101}", 120, 121, 101},
36 {"t,c,e{120,122,101}", 120, 122, 102},
34 {"t,c,e{120,121,101}", 120, 121, 100},
3735 },
3836 80: {
3937 {"t,c,e{-1,-1,0}", -1, -1, 0},
4644 {"t,c,e{100,50,40}", 100, 50, 40},
4745 {"t,c,e{100,99,79}", 100, 99, 79},
4846 {"t,c,e{100,100,80}", 100, 100, 80},
49 {"t,c,e{100,101,81}", 100, 101, 81},
50 {"t,c,e{100,102,82}", 100, 102, 82},
47 {"t,c,e{100,101,81}", 100, 101, 80},
5148 {"t,c,e{120,0,0}", 120, 0, 0},
5249 {"t,c,e{120,10,7}", 120, 10, 7},
5350 {"t,c,e{120,15,10}", 120, 15, 10},
5855 {"t,c,e{120,118,79}", 120, 118, 79},
5956 {"t,c,e{120,119,79}", 120, 119, 79},
6057 {"t,c,e{120,120,80}", 120, 120, 80},
61 {"t,c,e{120,121,81}", 120, 121, 81},
62 {"t,c,e{120,122,81}", 120, 122, 81},
58 {"t,c,e{120,121,81}", 120, 121, 80},
6359 },
6460 }
6561