mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Prefer to have widgets force a draw when their data changes. This should reduce draws (unless the user has a module installed that updates >= 1/sec, the old draw default). This should also remove a source of some of the race conditions that users were experiencing (though not all, there are still many).
43 lines
820 B
Go
43 lines
820 B
Go
package status
|
|
|
|
import (
|
|
"github.com/rivo/tview"
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type Widget struct {
|
|
wtf.TextWidget
|
|
|
|
CurrentIcon int
|
|
}
|
|
|
|
func NewWidget(app *tview.Application) *Widget {
|
|
widget := Widget{
|
|
TextWidget: wtf.NewTextWidget(app, "Status", "status", false),
|
|
CurrentIcon: 0,
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
widget.UpdateRefreshedAt()
|
|
widget.View.SetText(widget.animation())
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) animation() string {
|
|
icons := []string{"|", "/", "-", "\\", "|"}
|
|
next := icons[widget.CurrentIcon]
|
|
|
|
widget.CurrentIcon = widget.CurrentIcon + 1
|
|
if widget.CurrentIcon == len(icons) {
|
|
widget.CurrentIcon = 0
|
|
}
|
|
|
|
return next
|
|
}
|