This commit is contained in:
parent
e7a16c663a
commit
69dcd8418a
11
main.go
11
main.go
@ -116,6 +116,7 @@ func stopwatchUI(startTime time.Time) {
|
||||
|
||||
go func() {
|
||||
<-stop
|
||||
fmt.Println()
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
@ -137,22 +138,22 @@ func timerUI(startTime time.Time) {
|
||||
|
||||
go func() {
|
||||
<-stop
|
||||
fmt.Printf("\n")
|
||||
fmt.Println()
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
for {
|
||||
elapsed := time.Until(startTime)
|
||||
if elapsed.Milliseconds() == 0 {
|
||||
fmt.Printf("\n")
|
||||
break
|
||||
}
|
||||
fmt.Printf("\r%02dd %02dh %02dm %02ds %03dms",
|
||||
elapsed/(24*time.Hour),
|
||||
(elapsed%(24*time.Hour))/time.Hour,
|
||||
(elapsed%time.Hour)/time.Minute,
|
||||
(elapsed%time.Minute)/time.Second,
|
||||
(elapsed%time.Second)/time.Millisecond)
|
||||
if elapsed.Milliseconds() == 0 {
|
||||
fmt.Println()
|
||||
break
|
||||
}
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user