/* 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 . */ package main import ( "flag" "fmt" "math" "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 printVersion bool ) 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.") flag.BoolVar(&printVersion, "version", false, "print version and exit.") flag.Parse() } func main() { if printVersion { Version() os.Exit(0) } initNotifier() 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) } pominal := NewPominal( workTimeDuration, shortBreakTimeDuration, longBreakTimeDuration, maxWorkCycles, ) 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. // TODO: To be removed when TUI is implemented. 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, (remainingSecs/60)%60, remainingSecs%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() }