AppendETA
Vladimir Bauer
9 years ago
| 113 | 113 | func (b *Bar) AppendETA() *Bar { |
| 114 | 114 | b.AppendFunc(func(s *Statistics) string { |
| 115 | 115 | eta := time.Duration(s.Total-s.Completed) * s.TimePerItemEstimate |
| 116 | return fmt.Sprint(time.Duration(eta.Seconds()) * time.Second) | |
| 116 | return fmt.Sprintf("ETA %v", time.Duration(eta.Seconds())*time.Second) | |
| 117 | 117 | }) |
| 118 | 118 | return b |
| 119 | 119 | } |
| 128 | 128 | func (b *Bar) server() { |
| 129 | 129 | var current int |
| 130 | 130 | blockStartTime := time.Now() |
| 131 | buf := make([]byte, b.Width, b.Width+9) | |
| 131 | buf := make([]byte, b.Width, b.Width+24) | |
| 132 | 132 | var appendFuncs []DecoratorFunc |
| 133 | 133 | var prependFuncs []DecoratorFunc |
| 134 | 134 | for { |
| 149 | 149 | prependFuncs = append(prependFuncs, d.f) |
| 150 | 150 | } |
| 151 | 151 | case r := <-b.redrawRequestCh: |
| 152 | r.bufch <- b.draw(buf, current, appendFuncs) | |
| 152 | r.bufch <- b.draw(buf, current, appendFuncs, prependFuncs) | |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | func (b *Bar) draw(buf []byte, current int, appendFuncs []DecoratorFunc) []byte { | |
| 157 | func (b *Bar) draw(buf []byte, current int, appendFuncs, prependFuncs []DecoratorFunc) []byte { | |
| 158 | 158 | completedWidth := current * b.Width / b.total |
| 159 | 159 | |
| 160 | 160 | for i := 0; i < completedWidth; i++ { |