From b3d57a5f94c14d3fc4c7ca3392452367ff25d252 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 30 Aug 2022 19:47:45 +0200 Subject: [PATCH] update block date (infiny loop) --- blocks/date/main.go | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/blocks/date/main.go b/blocks/date/main.go index 4ad0cf0..92b40a5 100644 --- a/blocks/date/main.go +++ b/blocks/date/main.go @@ -21,26 +21,29 @@ func runCalendar(wg *sync.WaitGroup) { func main() { argFormat := flag.String("format", "%H:%M:%S %m-%d-%Y", "time format") flag.Parse() - - now := time.Now() - var wg sync.WaitGroup - if os.Getenv("BLOCK_BUTTON") == "1" { - wg.Add(1) - go runCalendar(&wg) + for { + now := time.Now() + + if os.Getenv("BLOCK_BUTTON") == "1" { + wg.Add(1) + go runCalendar(&wg) + } + + symbol := string(emoji.Calendar) + date := timefmt.Format(now, *argFormat) + + options := r.NewBlockOptions() + options.FullText = r.TextWithRightPadding(fmt.Sprintf("%s %s", symbol, date), r.FB{ + Foreground: r.Color("white"), + Background: r.Color("black4"), + }) + + block := r.Block("date", options) + fmt.Println(block) + time.Sleep(time.Millisecond * 500) } - symbol := string(emoji.Calendar) - date := timefmt.Format(now, *argFormat) - - options := r.NewBlockOptions() - options.FullText = r.TextWithRightPadding(fmt.Sprintf("%s %s", symbol, date), r.FB{ - Foreground: r.Color("white"), - Background: r.Color("black4"), - }) - - block := r.Block("date", options) - fmt.Println(block) wg.Wait() }