github.com/wtfutil/wtf@v0.43.0/modules/status/widget.go (about) 1 package status 2 3 import ( 4 "github.com/rivo/tview" 5 "github.com/wtfutil/wtf/view" 6 ) 7 8 type Widget struct { 9 view.TextWidget 10 11 CurrentIcon int 12 13 settings *Settings 14 } 15 16 func NewWidget(tviewApp *tview.Application, redrawChan chan bool, settings *Settings) *Widget { 17 widget := Widget{ 18 TextWidget: view.NewTextWidget(tviewApp, redrawChan, nil, settings.Common), 19 20 CurrentIcon: 0, 21 22 settings: settings, 23 } 24 25 return &widget 26 } 27 28 /* -------------------- Exported Functions -------------------- */ 29 30 func (widget *Widget) Refresh() { 31 widget.Redraw(widget.animation) 32 } 33 34 /* -------------------- Unexported Functions -------------------- */ 35 36 func (widget *Widget) animation() (string, string, bool) { 37 icons := []string{"|", "/", "-", "\\", "|"} 38 next := icons[widget.CurrentIcon] 39 40 widget.CurrentIcon++ 41 if widget.CurrentIcon == len(icons) { 42 widget.CurrentIcon = 0 43 } 44 45 return widget.CommonSettings().Title, next, false 46 }