1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/status/widget.go
2018-03-29 22:26:59 -07:00

52 lines
887 B
Go

package status
import (
"fmt"
"math/rand"
"time"
"github.com/rivo/tview"
)
type Widget struct {
RefreshedAt time.Time
View *tview.TextView
}
func NewWidget() *Widget {
widget := Widget{
RefreshedAt: time.Now(),
}
widget.addView()
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.View.SetTitle(" 🦊 Status ")
widget.RefreshedAt = time.Now()
widget.View.Clear()
fmt.Fprintf(widget.View, "%s", widget.contentFrom())
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) addView() {
view := tview.NewTextView()
view.SetBorder(true)
view.SetDynamicColors(true)
view.SetTitle(" BambooHR ")
widget.View = view
}
func (widget *Widget) contentFrom() string {
//return "cats and gods\ndogs and tacs"
return fmt.Sprint(rand.Intn(100))
}