benefit: panic at one place
Vladimir Bauer
3 years ago
| 456 | 456 |
for _, d := range s.pDecorators {
|
| 457 | 457 |
str := d.Decor(stat)
|
| 458 | 458 |
stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
|
| 459 | |
bufP.WriteString(str)
|
|
459 |
_, err := bufP.WriteString(str)
|
|
460 |
if err != nil {
|
|
461 |
panic(err)
|
|
462 |
}
|
| 460 | 463 |
}
|
| 461 | 464 |
if stat.AvailableWidth < 1 {
|
| 462 | 465 |
trunc := strings.NewReader(runewidth.Truncate(stripansi.Strip(bufP.String()), tw, "…"))
|
|
| 474 | 477 |
for _, d := range s.aDecorators {
|
| 475 | 478 |
str := d.Decor(stat)
|
| 476 | 479 |
stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
|
| 477 | |
bufA.WriteString(str)
|
|
480 |
_, err := bufA.WriteString(str)
|
|
481 |
if err != nil {
|
|
482 |
panic(err)
|
|
483 |
}
|
| 478 | 484 |
}
|
| 479 | 485 |
if stat.AvailableWidth < 1 {
|
| 480 | 486 |
trunc := strings.NewReader(runewidth.Truncate(stripansi.Strip(bufA.String()), tw, "…"))
|
|
| 482 | 488 |
return io.MultiReader(bufP, bufB, trunc, nlr)
|
| 483 | 489 |
}
|
| 484 | 490 |
|
| 485 | |
s.filler.Fill(bufB, stat)
|
|
491 |
err := s.filler.Fill(bufB, stat)
|
|
492 |
if err != nil {
|
|
493 |
panic(err)
|
|
494 |
}
|
| 486 | 495 |
|
| 487 | 496 |
return io.MultiReader(bufP, bufB, bufA, nlr)
|
| 488 | 497 |
}
|
| 87 | 87 |
// BarFillerOnComplete replaces bar's filler with message, on complete event.
|
| 88 | 88 |
func BarFillerOnComplete(message string) BarOption {
|
| 89 | 89 |
return BarFillerMiddleware(func(base BarFiller) BarFiller {
|
| 90 | |
return BarFillerFunc(func(w io.Writer, st decor.Statistics) {
|
|
90 |
return BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
|
| 91 | 91 |
if st.Completed {
|
| 92 | 92 |
_, err := io.WriteString(w, message)
|
| 93 | |
if err != nil {
|
| 94 | |
panic(err)
|
| 95 | |
}
|
| 96 | |
} else {
|
| 97 | |
base.Fill(w, st)
|
|
93 |
return err
|
| 98 | 94 |
}
|
|
95 |
return base.Fill(w, st)
|
| 99 | 96 |
})
|
| 100 | 97 |
})
|
| 101 | 98 |
}
|