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