aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-07 00:10:50 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-07 00:10:50 +0200
commit7109fe10f62236b0bbabbda6325143f4855833c4 (patch)
tree98a2b0983f6c0a70223c2a17830a2b039a521253
parent8f4d73beeedf4949c2d579010521313964241d94 (diff)
...
-rw-r--r--main.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/main.go b/main.go
index 97f9839..24cfb3c 100644
--- a/main.go
+++ b/main.go
@@ -19,12 +19,17 @@ type Opt struct {
run int
}
-type stateFn func(context.Context, chan string) stateFn
+type display struct {
+ s string
+ d time.Duration
+}
+
+type stateFn func(context.Context, chan display) stateFn
-func (o *Opt) doWork(ctx context.Context, c chan string) stateFn {
+func (o *Opt) doWork(ctx context.Context, c chan display) stateFn {
t := time.NewTimer(o.Work)
defer t.Stop()
- c <- fmt.Sprintf("Work %v run #%v", o.Work, o.run+1)
+ c <- display{"Work", o.Work}
select {
case <-ctx.Done():
return nil
@@ -33,17 +38,17 @@ func (o *Opt) doWork(ctx context.Context, c chan string) stateFn {
}
}
-func (o *Opt) doBreak(_ context.Context, _ chan string) stateFn {
+func (o *Opt) doBreak(_ context.Context, _ chan display) stateFn {
if o.run++; o.run%o.Runs == 0 {
return o.longBreak
}
return o.shortBreak
}
-func (o *Opt) shortBreak(ctx context.Context, c chan string) stateFn {
+func (o *Opt) shortBreak(ctx context.Context, c chan display) stateFn {
t := time.NewTimer(o.Short)
defer t.Stop()
- c <- fmt.Sprintf("Short %v", o.Short)
+ c <- display{"Short", o.Short}
select {
case <-ctx.Done():
return nil
@@ -52,10 +57,10 @@ func (o *Opt) shortBreak(ctx context.Context, c chan string) stateFn {
}
}
-func (o *Opt) longBreak(ctx context.Context, c chan string) stateFn {
+func (o *Opt) longBreak(ctx context.Context, c chan display) stateFn {
t := time.NewTimer(o.Long)
defer t.Stop()
- c <- fmt.Sprintf("Long %v", o.Long)
+ c <- display{"Long", o.Long}
select {
case <-ctx.Done():
return nil
@@ -64,8 +69,8 @@ func (o *Opt) longBreak(ctx context.Context, c chan string) stateFn {
}
}
-func notifier(ctx context.Context) chan string {
- c := make(chan string)
+func notifier(ctx context.Context) chan display {
+ c := make(chan display)
go func() {
defer close(c)
for v := range c {
@@ -73,7 +78,7 @@ func notifier(ctx context.Context) chan string {
case <-ctx.Done():
return
default:
- log.Println(v)
+ fmt.Println(v.s, v.d)
}
}
}()
@@ -99,7 +104,7 @@ func (o *Opt) pomodoro() {
}
}
-const timeBase = time.Minute
+const timeBase = time.Second
func main() {
var o Opt