43 lines
832 B
Go
43 lines
832 B
Go
package widgets
|
|
|
|
import (
|
|
"ArinDash/util"
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/mum4k/termdash/terminal/terminalapi"
|
|
"github.com/mum4k/termdash/widgetapi"
|
|
"github.com/mum4k/termdash/widgets/text"
|
|
)
|
|
|
|
type DateOptions struct {
|
|
}
|
|
|
|
func Date() DateOptions {
|
|
widgetOptions["DateOptions"] = createDate
|
|
return DateOptions{}
|
|
}
|
|
|
|
func createDate(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
|
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)
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
return nil
|
|
}
|
|
}
|
|
})
|
|
|
|
return widget
|
|
}
|