From 8db8efbdcbae9a2fd097474a0d0f90188bb3d89e Mon Sep 17 00:00:00 2001 From: Naveen Mahalingam Date: Fri, 10 Aug 2018 00:06:03 -0700 Subject: [PATCH] progress: fix rendering issue with PositionLeft (#51) --- cmd/demo-progress/demo.go | 2 +- progress/render.go | 6 ++++-- progress/render_test.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/demo-progress/demo.go b/cmd/demo-progress/demo.go index 008e3b6..fd44ec2 100644 --- a/cmd/demo-progress/demo.go +++ b/cmd/demo-progress/demo.go @@ -42,7 +42,7 @@ func trackSomething(pw progress.Writer, idx int64) { pw.AppendTracker(&tracker) - c := time.Tick(time.Millisecond * 100) + c := time.Tick(time.Millisecond * 250) for !tracker.IsDone() { select { case <-c: diff --git a/progress/render.go b/progress/render.go index 0e7b0fc..dd3dd76 100644 --- a/progress/render.go +++ b/progress/render.go @@ -102,6 +102,8 @@ func (p *Progress) renderTracker(out *strings.Builder, t *Tracker) { pInProgress = p.style.Chars.Finished50 } else if pFinishedDotsFraction > 0.25 { pInProgress = p.style.Chars.Finished25 + } else if pFinishedDotsFraction == 0 { + pInProgress = "" } p.renderTrackerProgress(out, t, p.style.Colors.Tracker.Sprintf("%s%s%s%s%s", @@ -128,7 +130,7 @@ func (p *Progress) renderTrackerProgress(out *strings.Builder, t *Tracker, track out.WriteString(p.style.Colors.Tracker.Sprint(trackerStr)) } p.renderTrackerStats(out, t) - out.WriteString("\n") + out.WriteRune('\n') } else { p.renderTrackerPercentage(out, t) if !p.hideTracker { @@ -139,7 +141,7 @@ func (p *Progress) renderTrackerProgress(out *strings.Builder, t *Tracker, track out.WriteString(p.style.Colors.Message.Sprint(p.style.Options.Separator)) out.WriteString(p.style.Colors.Message.Sprint(t.Message)) out.WriteString(p.style.Colors.Message.Sprint(t.Message)) - out.WriteRune(' ') + out.WriteRune('\n') } } diff --git a/progress/render_test.go b/progress/render_test.go index f91d27b..476a928 100644 --- a/progress/render_test.go +++ b/progress/render_test.go @@ -32,7 +32,7 @@ func generateWriter() Writer { pw.SetSortBy(SortByNone) pw.SetStyle(StyleDefault) pw.SetTrackerPosition(PositionRight) - pw.SetUpdateFrequency(time.Millisecond * 100) + pw.SetUpdateFrequency(time.Millisecond * 50) pw.Style().Colors = StyleColors{} pw.Style().Options = StyleOptions{ DoneString: "done!",