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"
|
|
|
|
"os"
|
|
|
|
"time"
|
2020-01-18 19:24:35 +00:00
|
|
|
|
|
|
|
"github.com/rivo/tview"
|
2019-05-30 23:19:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-09-18 09:08:12 +01:00
|
|
|
workTime string
|
|
|
|
shortBreakTime string
|
|
|
|
longBreakTime string
|
|
|
|
maxWorkSessions int
|
2019-08-14 20:07:27 +01:00
|
|
|
printVersion bool
|
2019-05-30 23:19:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-09-18 09:08:12 +01:00
|
|
|
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.")
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-12-01 20:30:20 +00:00
|
|
|
flag.Parse()
|
2019-05-30 23:19:53 +01:00
|
|
|
|
2019-08-14 20:07:27 +01:00
|
|
|
if printVersion {
|
|
|
|
Version()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2019-08-16 09:20:56 +01:00
|
|
|
initNotifier()
|
|
|
|
|
2019-09-18 09:08:12 +01:00
|
|
|
w, err := time.ParseDuration(workTime)
|
2019-05-30 23:19:53 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-09-18 09:08:12 +01:00
|
|
|
s, err := time.ParseDuration(shortBreakTime)
|
2019-05-30 23:19:53 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-09-18 09:08:12 +01:00
|
|
|
l, err := time.ParseDuration(longBreakTime)
|
2019-05-30 23:19:53 +01:00
|
|
|
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(
|
2019-09-18 09:08:12 +01:00
|
|
|
w.Seconds(),
|
|
|
|
s.Seconds(),
|
|
|
|
l.Seconds(),
|
|
|
|
maxWorkSessions,
|
2019-09-11 09:03:40 +01:00
|
|
|
)
|
2019-05-30 23:19:53 +01:00
|
|
|
|
2020-01-18 19:24:35 +00:00
|
|
|
app := tview.NewApplication()
|
|
|
|
infoUI := newInfoUI()
|
|
|
|
timerUI := newTimerUI(app)
|
|
|
|
flex := newFlex(infoUI, timerUI)
|
2019-05-30 23:19:53 +01:00
|
|
|
|
2020-01-18 19:24:35 +00:00
|
|
|
go pominal.Run(infoUI, timerUI)
|
2020-01-20 20:29:45 +00:00
|
|
|
if err := app.SetRoot(flex, false).SetFocus(flex).Run(); err != nil {
|
2020-01-18 19:24:35 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2019-05-30 23:19:53 +01:00
|
|
|
}
|