42 lines
676 B
Go
42 lines
676 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/martinlindhe/notify"
|
|
"github.com/schollz/progressbar/v3"
|
|
)
|
|
|
|
func main() {
|
|
d, err := time.ParseDuration(os.Args[1])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
deadline := time.Now().Add(d)
|
|
ctx, can := context.WithDeadline(context.Background(), deadline)
|
|
defer can()
|
|
|
|
n := int64(time.Until(deadline) / time.Second)
|
|
bar := progressbar.Default(n)
|
|
c := time.NewTicker(time.Second)
|
|
defer c.Stop()
|
|
func() {
|
|
for {
|
|
select {
|
|
case <-c.C:
|
|
case <-ctx.Done():
|
|
return
|
|
}
|
|
bar.Add(1)
|
|
}
|
|
}()
|
|
bar.Finish()
|
|
bar.Exit()
|
|
|
|
msg := "alerting after " + d.String()
|
|
notify.Alert(os.Args[0], msg, msg, "/dev/null")
|
|
}
|