diff --git a/bar.go b/bar.go index 61780dc..8551a41 100644 --- a/bar.go +++ b/bar.go @@ -387,26 +387,25 @@ func (s *bState) draw(stat decor.Statistics) io.Reader { for _, d := range s.pDecorators { str := d.Decor(stat) - stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str)) + stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str)) s.bufP.WriteString(str) } for _, d := range s.aDecorators { str := d.Decor(stat) - stat.OccupiedWidth += runewidth.StringWidth(stripansi.Strip(str)) + stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str)) s.bufA.WriteString(str) } - - s.bufA.WriteByte('\n') if !s.trimSpace { defer s.bufB.WriteByte(' ') s.bufB.WriteByte(' ') - stat.OccupiedWidth += 2 + stat.AvailableWidth -= 2 } s.filler.Fill(s.bufB, s.reqWidth, stat) + s.bufA.WriteByte('\n') return io.MultiReader(s.bufP, s.bufB, s.bufA) } @@ -434,11 +433,11 @@ func newStatistics(tw int, s *bState) decor.Statistics { return decor.Statistics{ - ID: s.id, - Completed: s.completeFlushed, - Total: s.total, - Current: s.current, - TermWidth: tw, + ID: s.id, + Completed: s.completeFlushed, + Total: s.total, + Current: s.current, + AvailableWidth: tw, } } diff --git a/bar_filler_bar.go b/bar_filler_bar.go index 0fe19c0..b27619d 100644 --- a/bar_filler_bar.go +++ b/bar_filler_bar.go @@ -99,7 +99,7 @@ } func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) { - width := internal.CalcWidthForBarFiller(reqWidth, stat.TermWidth-stat.OccupiedWidth) + width := internal.CalcWidthForBarFiller(reqWidth, stat.AvailableWidth) // don't count rLeft and rRight as progress brackets := s.rwidth[rLeft] + s.rwidth[rRight] diff --git a/bar_filler_spinner.go b/bar_filler_spinner.go index 845801f..c1afc6d 100644 --- a/bar_filler_spinner.go +++ b/bar_filler_spinner.go @@ -41,7 +41,7 @@ } func (s *spinnerFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) { - width := internal.CalcWidthForBarFiller(reqWidth, stat.TermWidth-stat.OccupiedWidth) + width := internal.CalcWidthForBarFiller(reqWidth, stat.AvailableWidth) frame := s.frames[s.count%uint(len(s.frames))] frameWidth := utf8.RuneCountInString(frame) diff --git a/decor/decorator.go b/decor/decorator.go index a7827ae..206fe79 100644 --- a/decor/decorator.go +++ b/decor/decorator.go @@ -47,12 +47,11 @@ // Statistics consists of progress related statistics, that Decorator // may need. type Statistics struct { - ID int - Completed bool - Total int64 - Current int64 - TermWidth int - OccupiedWidth int + ID int + Completed bool + Total int64 + Current int64 + AvailableWidth int } // Decorator interface.