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

Remove a ton of duplication around TextView widget creation

This commit is contained in:
Chris Cummer
2018-04-07 13:55:08 -07:00
committed by Chris Cummer
parent 52d57f1df4
commit b4bc6d4509
14 changed files with 129 additions and 90 deletions

View File

@@ -1,16 +0,0 @@
package wtf
import (
//"fmt"
"time"
)
type BaseWidget struct {
Name string
RefreshedAt time.Time
RefreshInt int
}
func (widget *BaseWidget) RefreshInterval() int {
return widget.RefreshInt
}

47
wtf/text_widget.go Normal file
View File

@@ -0,0 +1,47 @@
package wtf
import (
"fmt"
"time"
"github.com/olebedev/config"
"github.com/rivo/tview"
)
var Config *config.Config
type Position struct {
Top int
Left int
Width int
Height int
}
type TextWidget struct {
Enabled bool
Name string
Position Position
RefreshedAt time.Time
RefreshInt int
View *tview.TextView
}
func NewTextWidget(name string, configKey string) TextWidget {
widget := TextWidget{
Enabled: Config.UBool(fmt.Sprintf("wtf.%s.refreshInterval", configKey), false),
Name: name,
RefreshInt: Config.UInt(fmt.Sprintf("wtf.%s.refreshInterval", configKey)),
}
return widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) RefreshInterval() int {
return widget.RefreshInt
}
func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}