From 8a258225c9ee27f2bf663546aa6a642258631383 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 29 Mar 2018 18:06:42 -0700 Subject: [PATCH] Widgetized Status --- status/widget.go | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/status/widget.go b/status/widget.go index 34c85d6f..72e51743 100644 --- a/status/widget.go +++ b/status/widget.go @@ -2,17 +2,47 @@ package status import ( "fmt" + "time" "github.com/rivo/tview" ) -func Widget() tview.Primitive { - widget := tview.NewTextView() - widget.SetBorder(true) - widget.SetDynamicColors(true) - widget.SetTitle(" 🦊 Status ") - - fmt.Fprintf(widget, "%s", "cats and gods\ndogs and tacs") - - return widget +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() + + 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" }