ignore complete by means of SetTotal(int64, bool)
should fix #48 and #63
Vladimir Bauer
6 years ago
| 68 | 68 | trimSpace bool |
| 69 | 69 | toComplete bool |
| 70 | 70 | completeFlushed bool |
| 71 | ignoreComplete bool | |
| 71 | 72 | noPop bool |
| 72 | 73 | aDecorators []decor.Decorator |
| 73 | 74 | pDecorators []decor.Decorator |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | 172 | // 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`. | |
| 174 | 175 | func (b *Bar) SetTotal(total int64, complete bool) { |
| 175 | 176 | select { |
| 176 | 177 | case b.operateState <- func(s *bState) { |
| 178 | s.ignoreComplete = !complete | |
| 177 | 179 | if total <= 0 { |
| 178 | 180 | s.total = s.current |
| 179 | 181 | } else { |
| 180 | 182 | s.total = total |
| 181 | 183 | } |
| 182 | if complete && !s.toComplete { | |
| 184 | if !s.ignoreComplete && !s.toComplete { | |
| 183 | 185 | s.current = s.total |
| 184 | 186 | s.toComplete = true |
| 185 | 187 | go b.refreshTillShutdown() |
| 196 | 198 | s.iterated = true |
| 197 | 199 | s.lastN = current - s.current |
| 198 | 200 | s.current = current |
| 199 | if s.total > 0 && s.current >= s.total { | |
| 201 | if !s.ignoreComplete && s.current >= s.total { | |
| 200 | 202 | s.current = s.total |
| 201 | 203 | s.toComplete = true |
| 202 | 204 | go b.refreshTillShutdown() |
| 223 | 225 | s.iterated = true |
| 224 | 226 | s.lastN = n |
| 225 | 227 | s.current += n |
| 226 | if s.total > 0 && s.current >= s.total { | |
| 228 | if !s.ignoreComplete && s.current >= s.total { | |
| 227 | 229 | s.current = s.total |
| 228 | 230 | s.toComplete = true |
| 229 | 231 | go b.refreshTillShutdown() |
| 6 | 6 | if total <= 0 { |
| 7 | 7 | return 0 |
| 8 | 8 | } |
| 9 | if current >= total { | |
| 10 | return float64(width) | |
| 11 | } | |
| 9 | 12 | return float64(int64(width)*current) / float64(total) |
| 10 | 13 | } |
| 11 | 14 |
| 20 | 20 | {"t,c,e{100,50,50}", 100, 50, 50}, |
| 21 | 21 | {"t,c,e{100,99,99}", 100, 99, 99}, |
| 22 | 22 | {"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}, | |
| 25 | 24 | {"t,c,e{120,0,0}", 120, 0, 0}, |
| 26 | 25 | {"t,c,e{120,10,8}", 120, 10, 8}, |
| 27 | 26 | {"t,c,e{120,15,13}", 120, 15, 13}, |
| 32 | 31 | {"t,c,e{120,118,98}", 120, 118, 98}, |
| 33 | 32 | {"t,c,e{120,119,99}", 120, 119, 99}, |
| 34 | 33 | {"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}, | |
| 37 | 35 | }, |
| 38 | 36 | 80: { |
| 39 | 37 | {"t,c,e{-1,-1,0}", -1, -1, 0}, |
| 46 | 44 | {"t,c,e{100,50,40}", 100, 50, 40}, |
| 47 | 45 | {"t,c,e{100,99,79}", 100, 99, 79}, |
| 48 | 46 | {"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}, | |
| 51 | 48 | {"t,c,e{120,0,0}", 120, 0, 0}, |
| 52 | 49 | {"t,c,e{120,10,7}", 120, 10, 7}, |
| 53 | 50 | {"t,c,e{120,15,10}", 120, 15, 10}, |
| 58 | 55 | {"t,c,e{120,118,79}", 120, 118, 79}, |
| 59 | 56 | {"t,c,e{120,119,79}", 120, 119, 79}, |
| 60 | 57 | {"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}, | |
| 63 | 59 | }, |
| 64 | 60 | } |
| 65 | 61 | |