Add add and sub

master
Bel LaPointe 2020-02-17 14:45:11 -07:00
parent 7fe3934f07
commit df3d56f677
2 changed files with 17 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
) )
func main() { func main() {
@ -44,6 +45,14 @@ func listen(k *Keyboard, tp *TickPrinter, timer *Timer, stop func()) {
for { for {
key := <-k.Events key := <-k.Events
switch key { switch key {
case 'a':
timer.Add(time.Second)
case 'A':
timer.Add(time.Minute)
case 's':
timer.Sub(time.Second)
case 'S':
timer.Sub(time.Minute)
case 'p': case 'p':
timer.TogglePause() timer.TogglePause()
case 'z': case 'z':

View File

@ -89,3 +89,11 @@ func (t *Timer) Done() bool {
func (t *Timer) String() string { func (t *Timer) String() string {
return t.Typed(t) return t.Typed(t)
} }
func (t *Timer) Add(d time.Duration) {
t.From = t.From.Add(d)
}
func (t *Timer) Sub(d time.Duration) {
t.Add(time.Duration(-1) * d)
}