clean
parent
debfeaa0a6
commit
ea0bcfa40d
47
main.go
47
main.go
|
|
@ -67,16 +67,23 @@ func main() {
|
||||||
|
|
||||||
logger.Log("Quit with 'q', Pause with 'p', Reset with 'r'")
|
logger.Log("Quit with 'q', Pause with 'p', Reset with 'r'")
|
||||||
|
|
||||||
|
keych := keyChannel()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
last := time.Now()
|
last := time.Now()
|
||||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-monitor.C:
|
case <-monitor.C:
|
||||||
|
difference := time.Duration(time.Now().UnixNano() - last.UnixNano())
|
||||||
|
if difference > time.Second*10 {
|
||||||
|
keych <- 'p'
|
||||||
|
continue
|
||||||
|
}
|
||||||
if invert {
|
if invert {
|
||||||
cur += time.Duration(time.Now().UnixNano() - last.UnixNano())
|
cur += difference
|
||||||
} else {
|
} else {
|
||||||
cur -= time.Duration(time.Now().UnixNano() - last.UnixNano())
|
cur -= difference
|
||||||
}
|
}
|
||||||
last = time.Now()
|
last = time.Now()
|
||||||
case state := <-pause:
|
case state := <-pause:
|
||||||
|
|
@ -87,7 +94,7 @@ func main() {
|
||||||
monitor.Stop()
|
monitor.Stop()
|
||||||
}
|
}
|
||||||
case <-stop:
|
case <-stop:
|
||||||
logger.Log("")
|
logger.Logf()
|
||||||
confirm <- true
|
confirm <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -95,15 +102,8 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := keyboard.Open(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer keyboard.Close()
|
|
||||||
for {
|
for {
|
||||||
b, _, err := keyboard.GetKey()
|
b := <-keych
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
switch b {
|
switch b {
|
||||||
case 'q':
|
case 'q':
|
||||||
stop <- true
|
stop <- true
|
||||||
|
|
@ -123,7 +123,7 @@ func main() {
|
||||||
notified = false
|
notified = false
|
||||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||||
case 'z':
|
case 'z':
|
||||||
logger.Log("\n")
|
logger.Logf()
|
||||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,3 +199,26 @@ func alertTime(pRemains *time.Duration, target time.Duration, reverse, repeat bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func keyChannel() chan rune {
|
||||||
|
ch := make(chan rune, 20)
|
||||||
|
go func() {
|
||||||
|
if err := keyboard.Open(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
b, _, err := keyboard.GetKey()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
by := rune(b)
|
||||||
|
if by == 'q' {
|
||||||
|
keyboard.Close()
|
||||||
|
ch <- by
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ch <- by
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue