popup matters
parent
158399077f
commit
beeb6359c8
49
main.go
49
main.go
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue