mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package wtf
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/olebedev/config"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
var Config *config.Config
|
|
|
|
type TextWidget struct {
|
|
enabled bool
|
|
|
|
Name string
|
|
RefreshedAt time.Time
|
|
RefreshInt int
|
|
View *tview.TextView
|
|
|
|
Position
|
|
}
|
|
|
|
func NewTextWidget(name string, configKey string) TextWidget {
|
|
widget := TextWidget{
|
|
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
|
Name: name,
|
|
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
|
|
Position: Position{
|
|
top: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
|
|
left: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
|
|
height: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
|
|
width: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
|
|
},
|
|
}
|
|
|
|
widget.addView()
|
|
|
|
return widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *TextWidget) Disabled() bool {
|
|
return !widget.Enabled()
|
|
}
|
|
|
|
func (widget *TextWidget) Enabled() bool {
|
|
return widget.enabled
|
|
}
|
|
|
|
func (widget *TextWidget) RefreshInterval() int {
|
|
return widget.RefreshInt
|
|
}
|
|
|
|
func (widget *TextWidget) TextView() *tview.TextView {
|
|
return widget.View
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *TextWidget) addView() {
|
|
view := tview.NewTextView()
|
|
|
|
view.SetBorder(true)
|
|
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.normal")))
|
|
view.SetDynamicColors(true)
|
|
view.SetTitle(widget.Name)
|
|
view.SetWrap(false)
|
|
|
|
widget.View = view
|
|
}
|