mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
43 lines
744 B
Go
43 lines
744 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, nil, settings.common),
|
|
|
|
Battery: NewBattery(),
|
|
|
|
settings: settings,
|
|
}
|
|
|
|
widget.View.SetWrap(true)
|
|
|
|
return &widget
|
|
}
|
|
|
|
func (widget *Widget) content() (string, string, bool) {
|
|
content := fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
|
|
content += "\n"
|
|
content += widget.Battery.String()
|
|
return widget.CommonSettings().Title, content, true
|
|
}
|
|
|
|
func (widget *Widget) Refresh() {
|
|
widget.Battery.Refresh()
|
|
widget.Redraw(widget.content)
|
|
}
|