Dan Anglin
f0b46ed8b7
This commit removes the need to calculate the time remaining in a session and instead introduces a countdown counter which decrements at each one second 'tick'. This stabilizes the interface where it appeared that he timer was randomly pausing or skipping time. A summary of changes made in this commit includes: - Updated the command line flags so that they are easier to remember. - The work, short break and long break session times are now parsed and converted to type float64. These times represent the total amount of seconds. - Removal of timer and finish from Pominal. - The method that calculates the time remaining is removed. - A countdown counter is added to the Pominal type. - Updated alert message for the desktop notification. - Simplified the Run method by moving the logic to chosse the next session in a separate method.
104 lines
2.8 KiB
Go
104 lines
2.8 KiB
Go
/*
|
|
Pominal
|
|
Copyright (C) 2019 Daniel Anglin
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
workTimerLabel string = "Work"
|
|
shortBreakTimerLabel string = "Short break"
|
|
longBreakTimerLabel string = "Long break"
|
|
)
|
|
|
|
var (
|
|
workTime string
|
|
shortBreakTime string
|
|
longBreakTime string
|
|
maxWorkSessions int
|
|
printVersion bool
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(&workTime, "work", "25m", "sets the timer for your work session.")
|
|
flag.StringVar(&shortBreakTime, "short-break", "5m", "sets the timer for your short break.")
|
|
flag.StringVar(&longBreakTime, "long-break", "20m", "sets the timer for your long break.")
|
|
flag.IntVar(&maxWorkSessions, "max-work-sessions", 4, "sets the maximum number of work cycles to complete before taking a long break.")
|
|
flag.BoolVar(&printVersion, "version", false, "print version and exit.")
|
|
flag.Parse()
|
|
}
|
|
|
|
func main() {
|
|
|
|
if printVersion {
|
|
Version()
|
|
os.Exit(0)
|
|
}
|
|
|
|
initNotifier()
|
|
|
|
w, err := time.ParseDuration(workTime)
|
|
if err != nil {
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
s, err := time.ParseDuration(shortBreakTime)
|
|
if err != nil {
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
l, err := time.ParseDuration(longBreakTime)
|
|
if err != nil {
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
pominal := NewPominal(
|
|
w.Seconds(),
|
|
s.Seconds(),
|
|
l.Seconds(),
|
|
maxWorkSessions,
|
|
)
|
|
|
|
pominal.Run()
|
|
}
|
|
|
|
// printScreen prints the details of the Pominal session on screen including
|
|
// the current work session number, the timer's current label and the current countdoen.
|
|
// TODO: To be removed when TUI is implemented.
|
|
func printScreen(countdown float64, pominalCount, workSessionCount, maxWorkSession int, label string) {
|
|
clearScreen()
|
|
fmt.Printf("Pominal cycle: %d\nWork session: %d of %d\n\n", pominalCount, workSessionCount, maxWorkSession)
|
|
fmt.Printf("Session: %s\nTime remaining: %02d:%02d", label, int(countdown)/60, int(countdown)%60)
|
|
}
|
|
|
|
// clearScreen clears the terminal screen
|
|
// TODO: To be removed when TUI is implemented
|
|
func clearScreen() {
|
|
cmd := exec.Command("clear")
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Run()
|
|
}
|