aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-03-30 21:00:47 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-03-30 21:00:47 +0200
commit5e20c589653f7443cf01a8033f92757a43846c55 (patch)
tree7ecbf114c63be795d9aa38bf3fe8d013e5d6c56a
parent5b0b6973a5f93fc1e65c2f8b0dc0a4f1c378772e (diff)
...
-rw-r--r--main.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/main.go b/main.go
index 1d12ce7..921cc5e 100644
--- a/main.go
+++ b/main.go
@@ -31,7 +31,7 @@ func (o *Opt) doWork(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Work)
defer cancel()
- display(ctx, o.Tick, "working session")
+ o.display(ctx, "working session")
}
if o.run++; o.run%o.Runs == 0 {
return o.longBreak
@@ -46,7 +46,7 @@ func (o *Opt) shortBreak(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Short)
defer cancel()
- display(ctx, o.Tick, "short break")
+ o.display(ctx, "short break")
}
return o.doWork
}
@@ -58,27 +58,27 @@ func (o *Opt) longBreak(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Long)
defer cancel()
- display(ctx, o.Tick, "long break")
+ o.display(ctx, "long break")
}
return o.doWork
}
-func display(ctx context.Context, tick time.Duration, s string) {
+func (o *Opt) display(ctx context.Context, s string) {
go notify("Pomodoro timer", s)
dl, ok := ctx.Deadline()
if !ok {
return
}
total := time.Until(dl)
- ticker := time.NewTicker(tick)
+ ticker := time.NewTicker(o.Tick)
defer ticker.Stop()
defer fmt.Println("")
- for range ticker.C {
- fmt.Printf("\r%-20s %s", s, progress(total, time.Until(dl)))
+ for {
select {
case <-ctx.Done():
return
- default:
+ case <-ticker.C:
+ fmt.Printf("\r%-20s %s", s, progress(total, time.Until(dl)))
}
}
}