From 487358db51bc46161b85f8fa2d91bc3db81d6af1 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 9 Apr 2017 13:47:27 +0200 Subject: wip --- progress.go | 10 +++++++--- 1 file 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)) } } } -- cgit v1.2.3