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

40 lines
705 B
Go

package power
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
Battery *Battery
settings *Settings
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
Battery: NewBattery(),
settings: settings,
}
widget.View.SetWrap(true)
return &widget
}
func (widget *Widget) Refresh() {
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)
}