decor.Statistics holds AvailableWidth
Vladimir Bauer
6 years ago
| 386 | 386 |
func (s *bState) draw(stat decor.Statistics) io.Reader {
|
| 387 | 387 |
for _, d := range s.pDecorators {
|
| 388 | 388 |
str := d.Decor(stat)
|
| 389 | |
stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str))
|
|
389 |
stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
|
| 390 | 390 |
s.bufP.WriteString(str)
|
| 391 | 391 |
}
|
| 392 | 392 |
|
| 393 | 393 |
for _, d := range s.aDecorators {
|
| 394 | 394 |
str := d.Decor(stat)
|
| 395 | |
stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str))
|
|
395 |
stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
|
| 396 | 396 |
s.bufA.WriteString(str)
|
| 397 | 397 |
}
|
| 398 | |
|
| 399 | |
s.bufA.WriteByte('\n')
|
| 400 | 398 |
|
| 401 | 399 |
if !s.trimSpace {
|
| 402 | 400 |
defer s.bufB.WriteByte(' ')
|
| 403 | 401 |
s.bufB.WriteByte(' ')
|
| 404 | |
stat.OccupiedWidth += 2
|
|
402 |
stat.AvailableWidth -= 2
|
| 405 | 403 |
}
|
| 406 | 404 |
|
| 407 | 405 |
s.filler.Fill(s.bufB, s.reqWidth, stat)
|
| 408 | 406 |
|
|
407 |
s.bufA.WriteByte('\n')
|
| 409 | 408 |
return io.MultiReader(s.bufP, s.bufB, s.bufA)
|
| 410 | 409 |
}
|
| 411 | 410 |
|
|
| 433 | 432 |
|
| 434 | 433 |
func newStatistics(tw int, s *bState) decor.Statistics {
|
| 435 | 434 |
return decor.Statistics{
|
| 436 | |
ID: s.id,
|
| 437 | |
Completed: s.completeFlushed,
|
| 438 | |
Total: s.total,
|
| 439 | |
Current: s.current,
|
| 440 | |
TermWidth: tw,
|
|
435 |
ID: s.id,
|
|
436 |
Completed: s.completeFlushed,
|
|
437 |
Total: s.total,
|
|
438 |
Current: s.current,
|
|
439 |
AvailableWidth: tw,
|
| 441 | 440 |
}
|
| 442 | 441 |
}
|
| 443 | 442 |
|
| 98 | 98 |
}
|
| 99 | 99 |
|
| 100 | 100 |
func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
|
| 101 | |
width := internal.CalcWidthForBarFiller(reqWidth, stat.TermWidth-stat.OccupiedWidth)
|
|
101 |
width := internal.CalcWidthForBarFiller(reqWidth, stat.AvailableWidth)
|
| 102 | 102 |
|
| 103 | 103 |
// don't count rLeft and rRight as progress
|
| 104 | 104 |
brackets := s.rwidth[rLeft] + s.rwidth[rRight]
|
| 40 | 40 |
}
|
| 41 | 41 |
|
| 42 | 42 |
func (s *spinnerFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
|
| 43 | |
width := internal.CalcWidthForBarFiller(reqWidth, stat.TermWidth-stat.OccupiedWidth)
|
|
43 |
width := internal.CalcWidthForBarFiller(reqWidth, stat.AvailableWidth)
|
| 44 | 44 |
|
| 45 | 45 |
frame := s.frames[s.count%uint(len(s.frames))]
|
| 46 | 46 |
frameWidth := utf8.RuneCountInString(frame)
|
| 46 | 46 |
// Statistics consists of progress related statistics, that Decorator
|
| 47 | 47 |
// may need.
|
| 48 | 48 |
type Statistics struct {
|
| 49 | |
ID int
|
| 50 | |
Completed bool
|
| 51 | |
Total int64
|
| 52 | |
Current int64
|
| 53 | |
TermWidth int
|
| 54 | |
OccupiedWidth int
|
|
49 |
ID int
|
|
50 |
Completed bool
|
|
51 |
Total int64
|
|
52 |
Current int64
|
|
53 |
AvailableWidth int
|
| 55 | 54 |
}
|
| 56 | 55 |
|
| 57 | 56 |
// Decorator interface.
|