| 46 | 46 |
till int64
|
| 47 | 47 |
}
|
| 48 | 48 |
state struct {
|
|
49 |
id int
|
| 49 | 50 |
fill byte
|
| 50 | 51 |
empty byte
|
| 51 | 52 |
tip byte
|
|
| 66 | 67 |
}
|
| 67 | 68 |
)
|
| 68 | 69 |
|
| 69 | |
func newBar(ctx context.Context, wg *sync.WaitGroup, total int64, barWidth int) *Bar {
|
|
70 |
func newBar(ctx context.Context, wg *sync.WaitGroup, total int64, width, id int) *Bar {
|
| 70 | 71 |
b := &Bar{
|
| 71 | 72 |
fillCh: make(chan byte),
|
| 72 | 73 |
emptyCh: make(chan byte),
|
|
| 86 | 87 |
completeReqCh: make(chan struct{}),
|
| 87 | 88 |
done: make(chan struct{}),
|
| 88 | 89 |
}
|
| 89 | |
go b.server(ctx, wg, total, barWidth)
|
|
90 |
go b.server(ctx, wg, total, width, id)
|
| 90 | 91 |
return b
|
| 91 | 92 |
}
|
| 92 | 93 |
|
|
| 206 | 207 |
return s.appendFuncs
|
| 207 | 208 |
}
|
| 208 | 209 |
|
| 209 | |
// GetAppenders returns slice of prepender DecoratorFunc
|
|
210 |
// GetPrependers returns slice of prepender DecoratorFunc
|
| 210 | 211 |
func (b *Bar) GetPrependers() []DecoratorFunc {
|
| 211 | 212 |
s := b.getState()
|
| 212 | 213 |
return s.prependFuncs
|
|
| 219 | 220 |
return state.newStat()
|
| 220 | 221 |
}
|
| 221 | 222 |
|
|
223 |
// GetID returs id of the bar
|
|
224 |
func (b *Bar) GetID() int {
|
|
225 |
state := b.getState()
|
|
226 |
return state.id
|
|
227 |
}
|
|
228 |
|
| 222 | 229 |
// InProgress returns true, while progress is running
|
| 223 | 230 |
// Can be used as condition in for loop
|
| 224 | 231 |
func (b *Bar) InProgress() bool {
|
|
| 283 | 290 |
return state.draw(termWidth)
|
| 284 | 291 |
}
|
| 285 | 292 |
|
| 286 | |
func (b *Bar) server(ctx context.Context, wg *sync.WaitGroup, total int64, barWidth int) {
|
|
293 |
func (b *Bar) server(ctx context.Context, wg *sync.WaitGroup, total int64, width, id int) {
|
| 287 | 294 |
var completed bool
|
| 288 | 295 |
timeStarted := time.Now()
|
| 289 | 296 |
blockStartTime := timeStarted
|
| 290 | 297 |
state := state{
|
|
298 |
id: id,
|
| 291 | 299 |
fill: '=',
|
| 292 | 300 |
empty: '-',
|
| 293 | 301 |
tip: '>',
|
| 294 | 302 |
leftEnd: '[',
|
| 295 | 303 |
rightEnd: ']',
|
| 296 | 304 |
etaAlpha: 0.25,
|
| 297 | |
barWidth: barWidth,
|
|
305 |
barWidth: width,
|
| 298 | 306 |
total: total,
|
| 299 | 307 |
}
|
| 300 | 308 |
if total <= 0 {
|