diff --git a/font.go b/font.go index 7a62a0d..9cf62e9 100644 --- a/font.go +++ b/font.go @@ -90,3 +90,8 @@ var defaultFont = Font{ " ╚════╝ ", }, } + +var pausedText = Symbol{ + "█▀▄ ▄▀▄ █ █ ▄▀▀ ██▀ █▀▄", + "█▀ █▀█ ▀▄█ ▄██ █▄▄ █▄▀", +} diff --git a/main.go b/main.go index 4d38217..dd5a7c7 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,8 @@ const ( Flags ` - tick = time.Second + tick = time.Second + inputDelayMS = 500 * time.Millisecond ) var ( @@ -31,6 +32,8 @@ var ( queues chan termbox.Event startDone bool startX, startY int + inputStartTime time.Time + isPaused bool ) func main() { @@ -80,6 +83,7 @@ func stop() { func countdown(timeLeft time.Duration, countUp bool, sayTheTime bool) { var exitCode int + isPaused = false start(timeLeft) @@ -96,16 +100,24 @@ loop: for { select { case ev := <-queues: - if ev.Type == termbox.EventKey && (ev.Key == termbox.KeyEsc || ev.Key == termbox.KeyCtrlC) { + if ev.Key == termbox.KeyEsc || ev.Key == termbox.KeyCtrlC { exitCode = 1 break loop } - if ev.Ch == 'p' || ev.Ch == 'P' { - stop() - } - if ev.Ch == 'c' || ev.Ch == 'C' { - start(timeLeft) + + if pressTime := time.Now(); ev.Key == termbox.KeySpace && pressTime.Sub(inputStartTime) > inputDelayMS { + if isPaused { + start(timeLeft) + draw(timeLeft) + } else { + stop() + drawPause() + } + + isPaused = !isPaused + inputStartTime = time.Now() } + case <-ticker.C: if countUp { timeLeft += tick @@ -148,6 +160,15 @@ func draw(d time.Duration) { flush() } +func drawPause() { + w, h := termbox.Size() + startX := w/2 - pausedText.width()/2 + startY := h * 3 / 4 + + echo(pausedText, startX, startY) + flush() +} + func format(d time.Duration) string { d = d.Round(time.Second) h := d / time.Hour