updates
This commit is contained in:
parent
0013cb6d81
commit
0ceb6e092c
34
main.go
34
main.go
@ -27,6 +27,12 @@ func main() {
|
||||
namedStopwatch(args[0])
|
||||
} else if len(args) == 2 && (args[0] == "clear" || args[0] == "-c" || args[0] == "--clear") {
|
||||
clearStopwatch(args[1])
|
||||
} else if len(args) == 2 && (args[0] == "timer" || args[0] == "-t" || args[0] == "--timer") {
|
||||
d, err := time.ParseDuration(args[1])
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing duration:", err)
|
||||
}
|
||||
timerUI(time.Now().Add(d))
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,9 +131,35 @@ func stopwatchUI(startTime time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
func timerUI(startTime time.Time) {
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-stop
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
for {
|
||||
elapsed := time.Until(startTime)
|
||||
if elapsed.Milliseconds() == 0 {
|
||||
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)
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func printHelp() {
|
||||
fmt.Println("Usage:")
|
||||
fmt.Println(" stopwatch - Start a quick stopwatch")
|
||||
fmt.Println(" stopwatch [name] - Start or view a named stopwatch")
|
||||
fmt.Println(" stopwatch clear [name] - Remove a named stopwatch")
|
||||
fmt.Println(" stopwatch -t [time] - Start a quick timer")
|
||||
fmt.Println(" stopwatch -c [name] - Remove a named stopwatch")
|
||||
fmt.Println(" stopwatch -h - View help menu")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user