| 42 | 42 |
|
| 43 | 43 |
type (
|
| 44 | 44 |
bState struct {
|
| 45 | |
id int
|
| 46 | |
width int
|
| 47 | |
format fmtRunes
|
| 48 | |
etaAlpha float64
|
| 49 | |
total int64
|
| 50 | |
current int64
|
| 51 | |
dropRatio int64
|
| 52 | |
trimLeftSpace bool
|
| 53 | |
trimRightSpace bool
|
| 54 | |
completed bool
|
| 55 | |
aborted bool
|
| 56 | |
dynamic bool
|
| 57 | |
startTime time.Time
|
| 58 | |
timeElapsed time.Duration
|
| 59 | |
blockStartTime time.Time
|
| 60 | |
timePerItem time.Duration
|
| 61 | |
appendFuncs []decor.DecoratorFunc
|
| 62 | |
prependFuncs []decor.DecoratorFunc
|
| 63 | |
refill *refill
|
| 64 | |
bufP, bufB, bufA *bytes.Buffer
|
| 65 | |
panic string
|
|
45 |
id int
|
|
46 |
width int
|
|
47 |
format fmtRunes
|
|
48 |
etaAlpha float64
|
|
49 |
total int64
|
|
50 |
current int64
|
|
51 |
totalAutoIncrTrigger int64
|
|
52 |
totalAutoIncrBy int64
|
|
53 |
trimLeftSpace bool
|
|
54 |
trimRightSpace bool
|
|
55 |
completed bool
|
|
56 |
aborted bool
|
|
57 |
dynamic bool
|
|
58 |
startTime time.Time
|
|
59 |
timeElapsed time.Duration
|
|
60 |
blockStartTime time.Time
|
|
61 |
timePerItem time.Duration
|
|
62 |
appendFuncs []decor.DecoratorFunc
|
|
63 |
prependFuncs []decor.DecoratorFunc
|
|
64 |
refill *refill
|
|
65 |
bufP, bufB, bufA *bytes.Buffer
|
|
66 |
panic string
|
| 66 | 67 |
}
|
| 67 | 68 |
refill struct {
|
| 68 | 69 |
char rune
|
|
| 80 | 81 |
}
|
| 81 | 82 |
|
| 82 | 83 |
s := &bState{
|
| 83 | |
id: id,
|
| 84 | |
total: total,
|
| 85 | |
etaAlpha: etaAlpha,
|
| 86 | |
dropRatio: 10,
|
|
84 |
id: id,
|
|
85 |
total: total,
|
|
86 |
etaAlpha: etaAlpha,
|
|
87 |
totalAutoIncrTrigger: 10,
|
| 87 | 88 |
}
|
| 88 | 89 |
|
| 89 | 90 |
for _, opt := range options {
|
|
| 152 | 153 |
}
|
| 153 | 154 |
s.current += int64(n)
|
| 154 | 155 |
if s.dynamic {
|
| 155 | |
for s.current >= s.total {
|
| 156 | |
s.current -= s.current * s.dropRatio / 100
|
|
156 |
curp := decor.CalcPercentage(s.total, s.current, 100)
|
|
157 |
if 100-curp <= s.totalAutoIncrTrigger {
|
|
158 |
s.total += s.totalAutoIncrBy
|
| 157 | 159 |
}
|
| 158 | 160 |
} else if s.current >= s.total {
|
| 159 | 161 |
s.current = s.total
|
|
| 388 | 390 |
// bar s.width without leftEnd and rightEnd runes
|
| 389 | 391 |
barWidth := width - 2
|
| 390 | 392 |
|
| 391 | |
completedWidth := decor.CalcPercentage(s.total, s.current, barWidth)
|
|
393 |
completedWidth := decor.CalcPercentage(s.total, s.current, int64(barWidth))
|
| 392 | 394 |
|
| 393 | 395 |
if s.refill != nil {
|
| 394 | |
till := decor.CalcPercentage(s.total, s.refill.till, barWidth)
|
|
396 |
till := decor.CalcPercentage(s.total, s.refill.till, int64(barWidth))
|
| 395 | 397 |
// append refill rune
|
| 396 | |
for i := 0; i < till; i++ {
|
|
398 |
var i int64
|
|
399 |
for i = 0; i < till; i++ {
|
| 397 | 400 |
s.bufB.WriteRune(s.refill.char)
|
| 398 | 401 |
}
|
| 399 | |
for i := till; i < completedWidth; i++ {
|
|
402 |
for i = till; i < completedWidth; i++ {
|
| 400 | 403 |
s.bufB.WriteRune(s.format[rFill])
|
| 401 | 404 |
}
|
| 402 | 405 |
} else {
|
| 403 | |
for i := 0; i < completedWidth; i++ {
|
|
406 |
var i int64
|
|
407 |
for i = 0; i < completedWidth; i++ {
|
| 404 | 408 |
s.bufB.WriteRune(s.format[rFill])
|
| 405 | 409 |
}
|
| 406 | 410 |
}
|
| 407 | 411 |
|
| 408 | |
if completedWidth < barWidth && completedWidth > 0 {
|
|
412 |
if completedWidth < int64(barWidth) && completedWidth > 0 {
|
| 409 | 413 |
_, size := utf8.DecodeLastRune(s.bufB.Bytes())
|
| 410 | 414 |
s.bufB.Truncate(s.bufB.Len() - size)
|
| 411 | 415 |
s.bufB.WriteRune(s.format[rTip])
|
| 412 | 416 |
}
|
| 413 | 417 |
|
| 414 | |
for i := completedWidth; i < barWidth; i++ {
|
|
418 |
for i := completedWidth; i < int64(barWidth); i++ {
|
| 415 | 419 |
s.bufB.WriteRune(s.format[rEmpty])
|
| 416 | 420 |
}
|
| 417 | 421 |
|