main
parent
4e85f48d9e
commit
ca20b2a052
11
main.go
11
main.go
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gen2brain/beeep"
|
"github.com/gen2brain/beeep"
|
||||||
"github.com/schollz/progressbar/v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -74,24 +73,22 @@ func alertAfter(ctx context.Context, ntfy string, duration string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func alertAt(ctx context.Context, ntfy string, deadline time.Time, title, msg string) error {
|
func alertAt(ctx context.Context, ntfy string, deadline time.Time, title, msg string) error {
|
||||||
n := int64(time.Until(deadline) / time.Second)
|
// n := int64(time.Until(deadline) / time.Second)
|
||||||
bar := progressbar.Default(n)
|
|
||||||
c := time.NewTicker(time.Second)
|
c := time.NewTicker(time.Second)
|
||||||
defer c.Stop()
|
defer c.Stop()
|
||||||
func() {
|
func() {
|
||||||
ctx, can := context.WithDeadline(ctx, deadline)
|
ctx, can := context.WithDeadline(ctx, deadline)
|
||||||
defer can()
|
defer can()
|
||||||
for {
|
for ctx.Err() == nil {
|
||||||
select {
|
select {
|
||||||
case <-c.C:
|
case <-c.C:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bar.Add(1)
|
fmt.Printf("\r%s ", deadline.Sub(time.Now()))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
bar.Finish()
|
fmt.Println()
|
||||||
bar.Exit()
|
|
||||||
|
|
||||||
if err := ctx.Err(); err == nil {
|
if err := ctx.Err(); err == nil {
|
||||||
beeep.Alert(title, msg, "/dev/null")
|
beeep.Alert(title, msg, "/dev/null")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue