1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Added the System widget with basic build info

This commit is contained in:
Chris Cummer
2018-04-24 09:54:53 -07:00
parent 1559b1ea87
commit 7500a4031d
4 changed files with 84 additions and 24 deletions

57
system/widget.go Normal file
View File

@@ -0,0 +1,57 @@
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"),
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")
}
}