aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-09 19:50:22 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-09 19:50:22 +0200
commit7b530f5e52b12bb9beb241909bdc65838dc5a0b7 (patch)
treed9491268d0982f21d6ed486e53ebcd58e552a40c /main.go
parent487358db51bc46161b85f8fa2d91bc3db81d6af1 (diff)
combine files
Diffstat (limited to 'main.go')
-rw-r--r--main.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/main.go b/main.go
index 2cc50c4..2ad9538 100644
--- a/main.go
+++ b/main.go
@@ -3,9 +3,11 @@ package main
import (
"context"
"flag"
+ "fmt"
"log"
"os"
"os/signal"
+ "strings"
"time"
)
@@ -116,3 +118,32 @@ func main() {
flag.Parse()
o.pomodoro()
}
+
+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("%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) {
+ ctx, _ = context.WithTimeout(ctx, d)
+ start := time.Now()
+ defer fmt.Print("\n")
+ 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():
+ return
+ default:
+ }
+ }
+}