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

@ -13,18 +13,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("BambooHR", "bamboohr"),
Name: "BambooHR",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.bamboohr.refreshInterval", 900),
},
} }
widget.addView() widget.addView()

View File

@ -1,36 +1,96 @@
wtf: wtf:
refreshInterval: 1 refreshInterval: 1
bamboohr: bamboohr:
enabled: false
position:
top:
left:
width:
height:
refreshInterval: 900 refreshInterval: 900
url: "https://api.bamboohr.com/api/gateway.php" url: "https://api.bamboohr.com/api/gateway.php"
gcal: gcal:
currentIcon: "💥" currentIcon: "💥"
enabled: true
eventCount: 10 eventCount: 10
position:
top:
left:
width:
height:
refreshInterval: 300 refreshInterval: 300
secretFile: "~/.wtf/gcal/client_secret.json" secretFile: "~/.wtf/gcal/client_secret.json"
git: git:
commitCount: 5 commitCount: 5
enabled: true
position:
top:
left:
width:
height:
refreshInterval: 8 refreshInterval: 8
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf" repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
github: github:
enabled: true
organization: "BetterOfficeApps" organization: "BetterOfficeApps"
position:
top:
left:
width:
height:
refreshInterval: 300 refreshInterval: 300
repo: "core-api" repo: "core-api"
username: "senorprogrammer" username: "senorprogrammer"
jira: jira:
enabled: true
position:
top:
left:
width:
height:
refreshInterval: 900 refreshInterval: 900
newrelic: newrelic:
applicationId: 10549735 applicationId: 10549735
enabled: true
deployCount: 5 deployCount: 5
position:
top:
left:
width:
height:
refreshInterval: 900 refreshInterval: 900
opsgenie: opsgenie:
enabled: true
position:
top:
left:
width:
height:
refreshInterval: 21600 refreshInterval: 21600
security: security:
enabled: true
position:
top:
left:
width:
height:
refreshInterval: 3600 refreshInterval: 3600
status: status:
enabled: true
position:
top:
left:
width:
height:
refreshInterval: 1 refreshInterval: 1
weather: weather:
cityId: 6173331 cityId: 6173331
enabled: true
language: "EN" language: "EN"
position:
top:
left:
width:
height:
tempUnit: "C" tempUnit: "C"
refreshInterval: 900 refreshInterval: 900

View File

@ -15,18 +15,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Calendar", "gcal"),
Name: "Calendar",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.gcal.refreshInterval", 300),
},
} }
widget.addView() widget.addView()

View File

@ -15,17 +15,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Git", "git"),
Name: "Git",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.git.refreshInterval", 15),
},
} }
widget.addView() widget.addView()

View File

@ -14,17 +14,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Github", "github"),
Name: "Github",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.github.refreshInterval", 900),
},
} }
widget.addView() widget.addView()

View File

@ -13,17 +13,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("JIRA", "jira"),
Name: "JIRA",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.jira.refreshInterval", 900),
},
} }
widget.addView() widget.addView()

View File

@ -14,18 +14,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("New Relic", "newrelic"),
Name: "New Relic",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.newrelic.refreshInterval", 900),
},
} }
widget.addView() widget.addView()

View File

@ -14,17 +14,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("OpsGenie", "opsgenie"),
Name: "OpsGenie",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.opsgenie.refreshInterval", 21600),
},
} }
widget.addView() widget.addView()

View File

@ -14,17 +14,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Security", "security"),
Name: "Security",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.security.refreshInterval", 3600),
},
} }
widget.addView() widget.addView()

View File

@ -13,20 +13,15 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
Current int Current int
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Status", "status"),
Name: "Status", Current: 0,
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.status.refreshInterval", 1),
},
Current: 0,
} }
widget.addView() widget.addView()

View File

@ -15,17 +15,12 @@ import (
var Config *config.Config var Config *config.Config
type Widget struct { type Widget struct {
wtf.BaseWidget wtf.TextWidget
View *tview.TextView
} }
func NewWidget() *Widget { func NewWidget() *Widget {
widget := Widget{ widget := Widget{
BaseWidget: wtf.BaseWidget{ TextWidget: wtf.NewTextWidget("Weather", "weather"),
Name: "Weather",
RefreshedAt: time.Now(),
RefreshInt: Config.UInt("wtf.weather.refreshInterval", 900),
},
} }
widget.addView() widget.addView()

1
wtf.go
View File

@ -38,6 +38,7 @@ var Config = wtf.LoadConfigFile()
/* -------------------- Main -------------------- */ /* -------------------- Main -------------------- */
func main() { func main() {
wtf.Config = Config
bamboohr.Config = Config bamboohr.Config = Config
bamboo := bamboohr.NewWidget() bamboo := bamboohr.NewWidget()

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
}