Codebase list golang-github-vbauerster-mpb / 0d71a01
decor.Statistics holds AvailableWidth Vladimir Bauer 6 years ago
4 changed file(s) with 16 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
386386 func (s *bState) draw(stat decor.Statistics) io.Reader {
387387 for _, d := range s.pDecorators {
388388 str := d.Decor(stat)
389 stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str))
389 stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
390390 s.bufP.WriteString(str)
391391 }
392392
393393 for _, d := range s.aDecorators {
394394 str := d.Decor(stat)
395 stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str))
395 stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
396396 s.bufA.WriteString(str)
397397 }
398
399 s.bufA.WriteByte('\n')
400398
401399 if !s.trimSpace {
402400 defer s.bufB.WriteByte(' ')
403401 s.bufB.WriteByte(' ')
404 stat.OccupiedWidth += 2
402 stat.AvailableWidth -= 2
405403 }
406404
407405 s.filler.Fill(s.bufB, s.reqWidth, stat)
408406
407 s.bufA.WriteByte('\n')
409408 return io.MultiReader(s.bufP, s.bufB, s.bufA)
410409 }
411410
433432
434433 func newStatistics(tw int, s *bState) decor.Statistics {
435434 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,
441440 }
442441 }
443442
9898 }
9999
100100 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)
102102
103103 // don't count rLeft and rRight as progress
104104 brackets := s.rwidth[rLeft] + s.rwidth[rRight]
4040 }
4141
4242 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)
4444
4545 frame := s.frames[s.count%uint(len(s.frames))]
4646 frameWidth := utf8.RuneCountInString(frame)
4646 // Statistics consists of progress related statistics, that Decorator
4747 // may need.
4848 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
5554 }
5655
5756 // Decorator interface.