1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/system/widget.go
Chris Cummer 037c90db85 Widget#focus now a thing
Widgets can inform whether or not they should get tab focus.

Widgets that provide additional functionality should return true.

Widgets that have no extra capability should return false.

This allows the FocusTracker to only tab through and focus on widgets
for which it provides value.
2018-04-28 23:41:51 -07:00

58 lines
917 B
Go

package system
import (
"fmt"
"time"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object
var Config *config.Config
type Widget struct {
wtf.TextWidget
BuiltAt string
Version string
}
func NewWidget(builtAt, version string) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" System ", "system", false),
BuiltAt: builtAt,
Version: version,
}
return &widget
}
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
widget.View.Clear()
fmt.Fprintf(
widget.View,
"%6s: %s\n%6s: %s",
"Built",
widget.prettyBuiltAt(),
"Vers",
widget.Version,
)
widget.RefreshedAt = time.Now()
}
func (widget *Widget) prettyBuiltAt() string {
str, err := time.Parse("2006-01-02T15:04:05-0700", widget.BuiltAt)
if err != nil {
return err.Error()
} else {
return str.Format("Jan _2, 15:04")
}
}