fix: use math.Ceil to stabilise the timer display
This commit is contained in:
parent
705566e74f
commit
18cdd01dc8
1 changed files with 6 additions and 6 deletions
12
main.go
12
main.go
|
@ -21,6 +21,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -163,8 +164,6 @@ func (p *Pominal) Start(label string, workCycleCount int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.finish = time.Now().Add(d)
|
p.finish = time.Now().Add(d)
|
||||||
|
|
||||||
printScreen(p.TimeRemaining(), p.session, workCycleCount, p.maxWorkCycles, p.label)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncrementCount increments the pominal session count
|
// IncrementCount increments the pominal session count
|
||||||
|
@ -174,17 +173,18 @@ func (p *Pominal) IncrementCount() {
|
||||||
|
|
||||||
// TimeRemaining returns the remaining time left
|
// TimeRemaining returns the remaining time left
|
||||||
// on the timer
|
// on the timer
|
||||||
func (p *Pominal) TimeRemaining() time.Duration {
|
func (p *Pominal) TimeRemaining() float64 {
|
||||||
return p.finish.Sub(time.Now())
|
return p.finish.Sub(time.Now()).Seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// printScreen prints the details of the Pominal session on screen including
|
// 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
|
// the current work cycle number, the timer's current label and the time remaining
|
||||||
// on the timer.
|
// 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()
|
clearScreen()
|
||||||
|
remainingSecs := int(math.Ceil(remaining))
|
||||||
fmt.Printf("Pominal session: %d\nWork cycle: %d of %d\n\n", pominalCount, workCycle, maxWorkCycle)
|
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
|
// clearScreen clears the terminal screen
|
||||||
|
|
Loading…
Reference in a new issue