1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/power/widget.go
Chris Cummer f650bb1698 Remove the app.Draw() gorountine
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).
2018-09-24 14:40:57 -07:00

38 lines
648 B
Go

package power
import (
"fmt"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
Battery *Battery
}
func NewWidget(app *tview.Application) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, "Power", "power", false),
Battery: NewBattery(),
}
widget.View.SetWrap(true)
return &widget
}
func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()
widget.Battery.Refresh()
content := ""
content = content + fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
content = content + "\n"
content = content + widget.Battery.String()
widget.View.SetText(content)
}