1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/power/widget.go

41 lines
665 B
Go

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