2019-05-30 23:19:53 +01:00
|
|
|
/*
|
|
|
|
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"
|
2019-08-12 09:22:51 +01:00
|
|
|
"math"
|
2019-05-30 23:19:53 +01:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
workTimerLabel string = "Work"
|
|
|
|
shortBreakTimerLabel string = "Short break"
|
|
|
|
longBreakTimerLabel string = "Long break"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
workTimer string
|
|
|
|
shortBreakTimer string
|
|
|
|
longBreakTimer string
|
|
|
|
maxWorkCycles int
|
2019-08-14 20:07:27 +01:00
|
|
|
printVersion bool
|
2019-05-30 23:19:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&workTimer, "work-timer", "25m", "sets the timer for your work session.")
|
|
|
|
flag.StringVar(&shortBreakTimer, "short-break-timer", "5m", "sets the timer for your short break.")
|
|
|
|
flag.StringVar(&longBreakTimer, "long-break-timer", "20m", "sets the timer for your long break.")
|
|
|
|
flag.IntVar(&maxWorkCycles, "max-work-cycles", 4, "sets the maximum number of work cycles to complete before taking a long break.")
|
2019-08-14 20:07:27 +01:00
|
|
|
flag.BoolVar(&printVersion, "version", false, "print version and exit.")
|
2019-05-30 23:19:53 +01:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2019-08-14 20:07:27 +01:00
|
|
|
if printVersion {
|
|
|
|
Version()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-08-16 09:20:56 +01:00
|
|
|
initNotifier()
|
|
|
|
|
2019-05-30 23:19:53 +01:00
|
|
|
workTimeDuration, err := time.ParseDuration(workTimer)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
shortBreakTimeDuration, err := time.ParseDuration(shortBreakTimer)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
longBreakTimeDuration, err := time.ParseDuration(longBreakTimer)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-09-11 09:03:40 +01:00
|
|
|
pominal := NewPominal(
|
|
|
|
workTimeDuration,
|
|
|
|
shortBreakTimeDuration,
|
|
|
|
longBreakTimeDuration,
|
|
|
|
maxWorkCycles,
|
|
|
|
)
|
2019-05-30 23:19:53 +01:00
|
|
|
|
|
|
|
pominal.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2019-09-11 09:03:40 +01:00
|
|
|
// TODO: To be removed when TUI is implemented.
|
2019-08-12 09:22:51 +01:00
|
|
|
func printScreen(remaining float64, pominalCount, workCycle, maxWorkCycle int, label string) {
|
2019-05-30 23:19:53 +01:00
|
|
|
clearScreen()
|
2019-08-12 09:22:51 +01:00
|
|
|
remainingSecs := int(math.Ceil(remaining))
|
2019-05-30 23:19:53 +01:00
|
|
|
fmt.Printf("Pominal session: %d\nWork cycle: %d of %d\n\n", pominalCount, workCycle, maxWorkCycle)
|
2019-08-12 09:22:51 +01:00
|
|
|
fmt.Printf("Timer: %s\nTime remaining: %02d:%02d", label, (remainingSecs/60)%60, remainingSecs%60)
|
2019-05-30 23:19:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// clearScreen clears the terminal screen
|
2019-08-16 09:20:56 +01:00
|
|
|
// TODO: To be removed when TUI is implemented
|
2019-05-30 23:19:53 +01:00
|
|
|
func clearScreen() {
|
|
|
|
cmd := exec.Command("clear")
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Run()
|
|
|
|
}
|