Skip to content

Commit

Permalink
fix some minor readability/quality issues (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t authored Jul 11, 2021
1 parent 71ae72a commit f66f5f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
33 changes: 21 additions & 12 deletions cmd/demo-progress/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ var (
}
)

func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
total := idx * idx * idx * 250
incrementPerCycle := idx * int64(*numTrackers) * 250
func getMessage(idx int64, units *progress.Units) string {
var message string
switch units {
case &progress.UnitsBytes:
message = fmt.Sprintf("Downloading File #%3d", idx)
case &progress.UnitsCurrencyDollar, &progress.UnitsCurrencyEuro, &progress.UnitsCurrencyPound:
message = fmt.Sprintf("Transferring Amount #%3d", idx)
default:
message = fmt.Sprintf("Calculating Total #%3d", idx)
}
return message
}

func getUnits(idx int64) *progress.Units {
var units *progress.Units
switch {
case idx%5 == 0:
Expand All @@ -41,16 +51,15 @@ func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
default:
units = &progress.UnitsDefault
}
return units
}

var message string
switch units {
case &progress.UnitsBytes:
message = fmt.Sprintf("Downloading File #%3d", idx)
case &progress.UnitsCurrencyDollar, &progress.UnitsCurrencyEuro, &progress.UnitsCurrencyPound:
message = fmt.Sprintf("Transferring Amount #%3d", idx)
default:
message = fmt.Sprintf("Calculating Total #%3d", idx)
}
func trackSomething(pw progress.Writer, idx int64, updateMessage bool) {
total := idx * idx * idx * 250
incrementPerCycle := idx * int64(*numTrackers) * 250

units := getUnits(idx)
message := getMessage(idx, units)
tracker := progress.Tracker{Message: message, Total: total, Units: *units}
if idx == int64(*numTrackers) {
tracker.Total = 0
Expand Down
3 changes: 1 addition & 2 deletions progress/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func (p *Progress) Render() {
case <-p.done:
// always render the current state before finishing render in
// case it hasn't been shown yet
lastRenderLength = p.renderTrackers(lastRenderLength)

p.renderTrackers(lastRenderLength)
p.endRender()
return
}
Expand Down

0 comments on commit f66f5f1

Please sign in to comment.