Some refactoring
Vladimir Bauer
8 years ago
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | type ( |
| 43 | refill struct { | |
| 44 | char rune | |
| 45 | till int64 | |
| 46 | } | |
| 47 | 43 | state struct { |
| 48 | 44 | id int |
| 49 | 45 | width int |
| 67 | 63 | bufP, bufB, bufA *bytes.Buffer |
| 68 | 64 | panic string |
| 69 | 65 | } |
| 66 | refill struct { | |
| 67 | char rune | |
| 68 | till int64 | |
| 69 | } | |
| 70 | 70 | writeBuf struct { |
| 71 | 71 | buf []byte |
| 72 | 72 | completeAfterFlush bool |
| 113 | 113 | // RemoveBar removes bar at any time. |
| 114 | 114 | func (p *Progress) RemoveBar(b *Bar) bool { |
| 115 | 115 | result := make(chan bool, 1) |
| 116 | op := func(c *pConf) { | |
| 116 | select { | |
| 117 | case p.ops <- func(c *pConf) { | |
| 117 | 118 | var ok bool |
| 118 | 119 | for i, bar := range c.bars { |
| 119 | 120 | if bar == b { |
| 124 | 125 | } |
| 125 | 126 | } |
| 126 | 127 | result <- ok |
| 127 | } | |
| 128 | select { | |
| 129 | case p.ops <- op: | |
| 128 | }: | |
| 130 | 129 | return <-result |
| 131 | 130 | case <-p.quit: |
| 132 | 131 | return false |
| 136 | 135 | // BarCount returns bars count |
| 137 | 136 | func (p *Progress) BarCount() int { |
| 138 | 137 | result := make(chan int, 1) |
| 139 | op := func(c *pConf) { | |
| 138 | select { | |
| 139 | case p.ops <- func(c *pConf) { | |
| 140 | 140 | result <- len(c.bars) |
| 141 | } | |
| 142 | select { | |
| 143 | case p.ops <- op: | |
| 141 | }: | |
| 144 | 142 | return <-result |
| 145 | 143 | case <-p.quit: |
| 146 | 144 | return 0 |