aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-12 01:47:04 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-12 01:47:04 +0200
commitf013d67855055d7f56fb39134d988316554ca771 (patch)
tree707e787a054f52ea5a0b9769a3e0f9f5173e1fb2
parent910f7ee6dd0fff13237dc9ebde41d06c8395ed38 (diff)
tick interval
-rw-r--r--main.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/main.go b/main.go
index de27ce1..9de4825 100644
--- a/main.go
+++ b/main.go
@@ -15,19 +15,20 @@ type Opt struct {
Short time.Duration
Long time.Duration
Day time.Duration
+ Tick time.Duration
Runs int
run int
}
type stateFn func(context.Context) stateFn
-func display(ctx context.Context, s string) {
+func (o *Opt) display(ctx context.Context, s string) {
dl, ok := ctx.Deadline()
if !ok {
return
}
total := time.Until(dl)
- ticker := time.NewTicker(time.Second)
+ ticker := time.NewTicker(o.Tick)
defer ticker.Stop()
defer fmt.Println("")
for range ticker.C {
@@ -71,7 +72,7 @@ func (o *Opt) doWork(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Work)
defer cancel()
- display(ctx, "do work")
+ o.display(ctx, "do work")
}
if o.run++; o.run%o.Runs == 0 {
return o.longBreak
@@ -86,7 +87,7 @@ func (o *Opt) shortBreak(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Short)
defer cancel()
- display(ctx, "short break")
+ o.display(ctx, "short break")
}
return o.doWork
}
@@ -98,7 +99,7 @@ func (o *Opt) longBreak(ctx context.Context) stateFn {
default:
ctx, cancel := context.WithTimeout(ctx, o.Long)
defer cancel()
- display(ctx, "long break")
+ o.display(ctx, "long break")
}
return o.doWork
}
@@ -109,6 +110,7 @@ func main() {
flag.DurationVar(&o.Short, "short", 5*time.Minute, "short break")
flag.DurationVar(&o.Long, "long", 15*time.Minute, "long break")
flag.DurationVar(&o.Day, "day", 12*time.Hour, "work day")
+ flag.DurationVar(&o.Tick, "tick", time.Second, "update interval")
flag.IntVar(&o.Runs, "runs", 4, "work runs")
flag.Parse()