diff --git a/main.go b/main.go index e70cd45..e02b055 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ package main import ( "flag" "fmt" + "math" "os" "os/exec" "os/signal" @@ -163,8 +164,6 @@ func (p *Pominal) Start(label string, workCycleCount int) { } p.finish = time.Now().Add(d) - - printScreen(p.TimeRemaining(), p.session, workCycleCount, p.maxWorkCycles, p.label) } // IncrementCount increments the pominal session count @@ -174,17 +173,18 @@ func (p *Pominal) IncrementCount() { // TimeRemaining returns the remaining time left // on the timer -func (p *Pominal) TimeRemaining() time.Duration { - return p.finish.Sub(time.Now()) +func (p *Pominal) TimeRemaining() float64 { + return p.finish.Sub(time.Now()).Seconds() } // printScreen prints the details of the Pominal session on screen including // the current work cycle number, the timer's current label and the time remaining // on the timer. -func printScreen(remaining time.Duration, pominalCount, workCycle, maxWorkCycle int, label string) { +func printScreen(remaining float64, pominalCount, workCycle, maxWorkCycle int, label string) { clearScreen() + remainingSecs := int(math.Ceil(remaining)) fmt.Printf("Pominal session: %d\nWork cycle: %d of %d\n\n", pominalCount, workCycle, maxWorkCycle) - fmt.Printf("Timer: %s\nTime remaining: %02d:%02d", label, int(remaining.Minutes()), int(remaining.Seconds())%60) + fmt.Printf("Timer: %s\nTime remaining: %02d:%02d", label, (remainingSecs/60)%60, remainingSecs%60) } // clearScreen clears the terminal screen