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:
parent
1559b1ea87
commit
7500a4031d
2
Makefile
2
Makefile
@ -1,2 +1,2 @@
|
|||||||
install:
|
install:
|
||||||
go install -ldflags="-X main.version=$(shell git describe --always --abbrev=6 --dirty=-dev)"
|
go install -ldflags="-X main.version=$(shell git describe --always --abbrev=6 --dirty=-dev) -X main.builtat=$(shell date +%FT%T%z)"
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package status
|
package status
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
//"fmt"
|
||||||
//"sort"
|
|
||||||
//"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
@ -17,14 +15,12 @@ type Widget struct {
|
|||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
Current int
|
Current int
|
||||||
Version string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(version string) *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" 🎉 Status ", "status"),
|
TextWidget: wtf.NewTextWidget(" 🎉 Status ", "status"),
|
||||||
Current: 0,
|
Current: 0,
|
||||||
Version: version,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
@ -37,28 +33,28 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, w, _ := widget.View.GetInnerRect()
|
//_, _, w, _ := widget.View.GetInnerRect()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
fmt.Fprintf(
|
//fmt.Fprintf(
|
||||||
widget.View,
|
//widget.View,
|
||||||
fmt.Sprintf("\n%%%ds", w-1),
|
//fmt.Sprintf("%%%ds\n", w-1),
|
||||||
widget.Version,
|
//widget.Version,
|
||||||
)
|
//)
|
||||||
|
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) animation() string {
|
//func (widget *Widget) animation() string {
|
||||||
icons := []string{"👍", "🤜", "🤙", "🤜", "🤘", "🤜", "✊", "🤜", "👌", "🤜"}
|
//icons := []string{"👍", "🤜", "🤙", "🤜", "🤘", "🤜", "✊", "🤜", "👌", "🤜"}
|
||||||
next := icons[widget.Current]
|
//next := icons[widget.Current]
|
||||||
|
|
||||||
widget.Current = widget.Current + 1
|
//widget.Current = widget.Current + 1
|
||||||
if widget.Current == len(icons) {
|
//if widget.Current == len(icons) {
|
||||||
widget.Current = 0
|
//widget.Current = 0
|
||||||
}
|
//}
|
||||||
|
|
||||||
return next
|
//return next
|
||||||
}
|
//}
|
||||||
|
57
system/widget.go
Normal file
57
system/widget.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
11
wtf.go
11
wtf.go
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/opsgenie"
|
"github.com/senorprogrammer/wtf/opsgenie"
|
||||||
"github.com/senorprogrammer/wtf/security"
|
"github.com/senorprogrammer/wtf/security"
|
||||||
"github.com/senorprogrammer/wtf/status"
|
"github.com/senorprogrammer/wtf/status"
|
||||||
|
"github.com/senorprogrammer/wtf/system"
|
||||||
"github.com/senorprogrammer/wtf/textfile"
|
"github.com/senorprogrammer/wtf/textfile"
|
||||||
"github.com/senorprogrammer/wtf/todo"
|
"github.com/senorprogrammer/wtf/todo"
|
||||||
"github.com/senorprogrammer/wtf/weather"
|
"github.com/senorprogrammer/wtf/weather"
|
||||||
@ -135,7 +136,11 @@ var FocusTracker wtf.FocusTracker
|
|||||||
var Widgets []wtf.TextViewer
|
var Widgets []wtf.TextViewer
|
||||||
|
|
||||||
var result = wtf.CreateConfigDir()
|
var result = wtf.CreateConfigDir()
|
||||||
var version = "dev"
|
|
||||||
|
var (
|
||||||
|
builtat = "now"
|
||||||
|
version = "dev"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flagConf := flag.String("config", "~/.wtf/config.yml", "Path to config file")
|
flagConf := flag.String("config", "~/.wtf/config.yml", "Path to config file")
|
||||||
@ -170,6 +175,7 @@ func main() {
|
|||||||
opsgenie.Config = Config
|
opsgenie.Config = Config
|
||||||
security.Config = Config
|
security.Config = Config
|
||||||
status.Config = Config
|
status.Config = Config
|
||||||
|
system.Config = Config
|
||||||
textfile.Config = Config
|
textfile.Config = Config
|
||||||
todo.Config = Config
|
todo.Config = Config
|
||||||
weather.Config = Config
|
weather.Config = Config
|
||||||
@ -184,7 +190,8 @@ func main() {
|
|||||||
newrelic.NewWidget(),
|
newrelic.NewWidget(),
|
||||||
opsgenie.NewWidget(),
|
opsgenie.NewWidget(),
|
||||||
security.NewWidget(),
|
security.NewWidget(),
|
||||||
status.NewWidget(version),
|
status.NewWidget(),
|
||||||
|
system.NewWidget(builtat, version),
|
||||||
textfile.NewWidget(),
|
textfile.NewWidget(),
|
||||||
todo.NewWidget(),
|
todo.NewWidget(),
|
||||||
weather.NewWidget(),
|
weather.NewWidget(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user