eta good
parent
d810f4e3f0
commit
13885f7ba6
43
main.go
43
main.go
|
|
@ -21,12 +21,14 @@ func main() {
|
|||
var interval string
|
||||
var repeat bool
|
||||
var invert bool
|
||||
var eta bool
|
||||
|
||||
flag.BoolVar(&repeat, "repeat", true, "Whether to repeat the timer on complete")
|
||||
flag.BoolVar(&invert, "stopwatch", false, "Use as a stopwatch")
|
||||
flag.StringVar(&duration, "duration", "30m", "How long the timer should be")
|
||||
flag.StringVar(&offset, "offset", "0m", "How much time the initial time should skip")
|
||||
flag.StringVar(&interval, "interval", "500ms", "Interval duration")
|
||||
flag.BoolVar(&eta, "eta", false, "Whether to display the ending time")
|
||||
flag.Parse()
|
||||
|
||||
tickerInterval, err := time.ParseDuration(interval)
|
||||
|
|
@ -66,7 +68,7 @@ func main() {
|
|||
|
||||
go func() {
|
||||
last := time.Now()
|
||||
printTime(&cur, base, &delim, invert, repeat)
|
||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||
for {
|
||||
select {
|
||||
case <-monitor.C:
|
||||
|
|
@ -88,7 +90,7 @@ func main() {
|
|||
confirm <- true
|
||||
return
|
||||
}
|
||||
printTime(&cur, base, &delim, invert, repeat)
|
||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -112,25 +114,22 @@ func main() {
|
|||
case 'r':
|
||||
skip = time.Duration(0)
|
||||
originalStart = time.Now()
|
||||
cur = base
|
||||
if invert {
|
||||
cur = time.Duration(0)
|
||||
} else {
|
||||
cur = base
|
||||
}
|
||||
notified = false
|
||||
printTime(&cur, base, &delim, invert, repeat)
|
||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||
case 'z':
|
||||
fmt.Printf("\n")
|
||||
printTime(&cur, base, &delim, invert, repeat)
|
||||
/*
|
||||
fmt.Printf("\nnow:\t%v\nstart:\t%v\ndiff:\t%v\n", time.Now().UnixNano()/int64(time.Second), originalStart.UnixNano()/int64(time.Second), (time.Now().UnixNano()-originalStart.UnixNano())/int64(time.Second))
|
||||
if invert {
|
||||
cur = skip + time.Duration(time.Now().UnixNano()-originalStart.UnixNano())
|
||||
} else {
|
||||
cur = base - skip - time.Duration(time.Now().UnixNano()-originalStart.UnixNano())
|
||||
}
|
||||
*/
|
||||
printTime(&cur, base, &delim, invert, repeat, eta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printTime(pRemains *time.Duration, target time.Duration, delim *rune, reverse bool, repeat bool) {
|
||||
func printTime(pRemains *time.Duration, target time.Duration, delim *rune, reverse bool, repeat bool, eta bool) {
|
||||
var final string
|
||||
remains := *pRemains
|
||||
sec := remains.Seconds()
|
||||
min := int(sec / 60.0)
|
||||
|
|
@ -156,16 +155,22 @@ func printTime(pRemains *time.Duration, target time.Duration, delim *rune, rever
|
|||
tdelim = ':'
|
||||
go alertTime(pRemains, target, reverse, repeat)
|
||||
}
|
||||
at := fmt.Sprintf("%2d%c%02d%c%02d", hrs, byte(*delim), min, byte(*delim), seconds)
|
||||
rem := fmt.Sprintf("%2d%c%02d%c%02d", rHrs, tdelim, rMin, tdelim, rSec)
|
||||
fmt.Printf("\rRemaining: %s \tAt: %s ", rem, at)
|
||||
at := fmt.Sprintf("%2d%c%02d%c%02d ", hrs, byte(*delim), min, byte(*delim), seconds)
|
||||
rem := fmt.Sprintf("%2d%c%02d%c%02d ", rHrs, tdelim, rMin, tdelim, rSec)
|
||||
rem = fmt.Sprintf("Remaining: %s \tAt: %s ", rem, at)
|
||||
if eta {
|
||||
rem = fmt.Sprintf("%s \tETA: %s", rem, time.Unix(0, (time.Now().UnixNano()+target.Nanoseconds()-pRemains.Nanoseconds())).Format("3:04"))
|
||||
}
|
||||
final = rem
|
||||
} else {
|
||||
rem := fmt.Sprintf("%2d%c%02d%c%02d", hrs, byte(*delim), min, byte(*delim), seconds)
|
||||
fmt.Printf("\rRemaining: %s ", rem)
|
||||
rem := fmt.Sprintf("%2d%c%02d%c%02d ", hrs, byte(*delim), min, byte(*delim), seconds)
|
||||
final = fmt.Sprintf("Remaining: %s ", rem)
|
||||
final = fmt.Sprintf("%s \tETA: %s", final, time.Unix(0, time.Now().UnixNano()+pRemains.Nanoseconds()).Format("3:04"))
|
||||
if remains < 0 {
|
||||
go alertTime(pRemains, target, reverse, repeat)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\r%s", final)
|
||||
}
|
||||
|
||||
func alertTime(pRemains *time.Duration, target time.Duration, reverse, repeat bool) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue