1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/status/widget.go
Chris Cummer beb0c43b07 Add character identifiers to focusable widgets
When no widget has focus, press the letter key to focus on the widget
assigned to that letter.

Example:

    GitHub (d)

    Press "d" to focus on the GitHub widget.
2018-07-30 15:51:19 -07:00

42 lines
768 B
Go

package status
import (
"github.com/senorprogrammer/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
CurrentIcon int
}
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("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
}