popup matters

master
Bel LaPointe 2018-04-09 11:36:52 -06:00
parent 158399077f
commit beeb6359c8
1 changed files with 42 additions and 7 deletions

49
main.go
View File

@ -7,8 +7,11 @@ import (
"time"
"github.com/eiannone/keyboard"
"github.com/everdev/mack"
)
var notified = false
func main() {
var duration string
var offset string
@ -60,7 +63,7 @@ func main() {
go func() {
last := time.Now()
printTime(cur, base, &delim, invert)
printTime(&cur, base, &delim, invert)
for {
select {
case <-monitor.C:
@ -81,7 +84,7 @@ func main() {
return
}
last = time.Now()
printTime(cur, base, &delim, invert)
printTime(&cur, base, &delim, invert)
}
}()
@ -106,10 +109,13 @@ func main() {
}
}
func printTime(remains time.Duration, target time.Duration, delim *rune, reverse bool) {
func printTime(pRemains *time.Duration, target time.Duration, delim *rune, reverse bool) {
remains := *pRemains
sec := remains.Seconds()
hrs := int(sec / 60.0)
min := int(sec / 60.0)
seconds := int(sec) % 60
hrs := min / 60
min = min % 60
if *delim == ':' {
*delim = ' '
} else {
@ -117,10 +123,39 @@ func printTime(remains time.Duration, target time.Duration, delim *rune, reverse
}
if reverse {
remains := target - remains
rHrs := int(remains.Seconds() / 60.0)
rMin := int(remains.Seconds() / 60.0)
rSec := int(remains.Seconds()) % 60
fmt.Printf("\rAt: %d%c%02d\tRemaining: %d%c%02d", hrs, byte(*delim), seconds, rHrs, byte(*delim), rSec)
rHrs := rMin / 60
rMin = rMin % 60
tdelim := byte(*delim)
if remains < 0 {
rMin = 0
rSec = 0
rHrs = 0
tdelim = ':'
go alertTime(pRemains, target, reverse)
}
fmt.Printf("\rAt: %2d%c%02d%c%02d\tRemaining: %2d%c%02d%c%02d", hrs, byte(*delim), min, byte(*delim), seconds, rHrs, tdelim, rMin, tdelim, rSec)
} else {
fmt.Printf("\rRemaining: %d%c%02d", hrs, byte(*delim), seconds)
fmt.Printf("\rRemaining: %2d%c%02d%c%02d", hrs, byte(*delim), min, byte(*delim), seconds)
if remains < 0 {
go alertTime(pRemains, target, reverse)
}
}
}
func alertTime(pRemains *time.Duration, target time.Duration, reverse bool) {
if !notified {
notified = true
_, err := mack.Alert("Alert")
if err != nil {
panic(err)
}
if reverse {
*pRemains -= target
} else {
*pRemains += target
}
notified = false
}
}