Refactor date and clock widgets to simplify periodic updates and remove redundant ticker logic.
This commit is contained in:
+4
-12
@@ -22,20 +22,12 @@ func createDate(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widg
|
||||
widget := util.PanicOnErrorWithResult(text.New())
|
||||
|
||||
go util.Periodic(ctx, 1*time.Second, func() error {
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
now := time.Now()
|
||||
if err := widget.Write(now.Format("Monday 2.1.2006"), text.WriteReplace()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
now := time.Now()
|
||||
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
}
|
||||
if err := widget.Write(now.Format("Monday 2.1.2006"), text.WriteReplace()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return widget
|
||||
|
||||
Reference in New Issue
Block a user