aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-09 13:47:27 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-09 13:47:27 +0200
commit487358db51bc46161b85f8fa2d91bc3db81d6af1 (patch)
treeb8b96a8edae8d73db3cfe130c32cf535cb472019
parent195c098360cf67e4918b069b905c89d6d510fac4 (diff)
wip
-rw-r--r--progress.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/progress.go b/progress.go
index 51effbe..3f5df90 100644
--- a/progress.go
+++ b/progress.go
@@ -15,11 +15,16 @@ Work 100% |**********************....| 25m0s ETA
*/
func progress(current, max time.Duration) string {
+ if current > max {
+ current = max
+ }
width := time.Duration(40)
n := width * current / max
done := strings.Repeat("*", int(n))
left := strings.Repeat(".", int(width-n))
- return fmt.Sprintf("|%v%v| %3d%%", done, left, 100*current/max)
+ return fmt.Sprintf("%3d%% |%v%v| %6s/%-6s",
+ 100*current/max, done, left,
+ current-current%time.Second, max-max%time.Second)
}
func count(ctx context.Context, s string, d time.Duration) {
@@ -29,12 +34,11 @@ func count(ctx context.Context, s string, d time.Duration) {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for t := range ticker.C {
+ fmt.Printf("\r%-16s %v", s, progress(t.Sub(start), d))
select {
case <-ctx.Done():
- fmt.Printf("\r%-20s %5s %v", s, d, progress(d, d))
return
default:
- fmt.Printf("\r%-20s %5s %v", s, d, progress(t.Sub(start), d))
}
}
}