35 lines
685 B
Go
35 lines
685 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 {
|
|
now := time.Now()
|
|
|
|
if err := widget.Write(now.Format("Monday 2.1.2006"), text.WriteReplace()); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
})
|
|
|
|
return widget
|
|
}
|