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:
parent
52d57f1df4
commit
b4bc6d4509
@ -13,18 +13,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "BambooHR",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.bamboohr.refreshInterval", 900),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("BambooHR", "bamboohr"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
60
config.yml
60
config.yml
@ -1,36 +1,96 @@
|
||||
wtf:
|
||||
refreshInterval: 1
|
||||
bamboohr:
|
||||
enabled: false
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 900
|
||||
url: "https://api.bamboohr.com/api/gateway.php"
|
||||
gcal:
|
||||
currentIcon: "💥"
|
||||
enabled: true
|
||||
eventCount: 10
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 300
|
||||
secretFile: "~/.wtf/gcal/client_secret.json"
|
||||
git:
|
||||
commitCount: 5
|
||||
enabled: true
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 8
|
||||
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
|
||||
github:
|
||||
enabled: true
|
||||
organization: "BetterOfficeApps"
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 300
|
||||
repo: "core-api"
|
||||
username: "senorprogrammer"
|
||||
jira:
|
||||
enabled: true
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 900
|
||||
newrelic:
|
||||
applicationId: 10549735
|
||||
enabled: true
|
||||
deployCount: 5
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 900
|
||||
opsgenie:
|
||||
enabled: true
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 21600
|
||||
security:
|
||||
enabled: true
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 3600
|
||||
status:
|
||||
enabled: true
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
refreshInterval: 1
|
||||
weather:
|
||||
cityId: 6173331
|
||||
enabled: true
|
||||
language: "EN"
|
||||
position:
|
||||
top:
|
||||
left:
|
||||
width:
|
||||
height:
|
||||
tempUnit: "C"
|
||||
refreshInterval: 900
|
||||
|
@ -15,18 +15,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Calendar",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.gcal.refreshInterval", 300),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Calendar", "gcal"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -15,17 +15,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Git",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.git.refreshInterval", 15),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Git", "git"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -14,17 +14,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Github",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.github.refreshInterval", 900),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Github", "github"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -13,17 +13,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "JIRA",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.jira.refreshInterval", 900),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("JIRA", "jira"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -14,18 +14,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "New Relic",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.newrelic.refreshInterval", 900),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("New Relic", "newrelic"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -14,17 +14,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "OpsGenie",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.opsgenie.refreshInterval", 21600),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("OpsGenie", "opsgenie"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -14,17 +14,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Security",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.security.refreshInterval", 3600),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Security", "security"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -13,19 +13,14 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
wtf.TextWidget
|
||||
|
||||
Current int
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Status",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.status.refreshInterval", 1),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Status", "status"),
|
||||
Current: 0,
|
||||
}
|
||||
|
||||
|
@ -15,17 +15,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
wtf.TextWidget
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Weather",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.weather.refreshInterval", 900),
|
||||
},
|
||||
TextWidget: wtf.NewTextWidget("Weather", "weather"),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
1
wtf.go
1
wtf.go
@ -38,6 +38,7 @@ var Config = wtf.LoadConfigFile()
|
||||
/* -------------------- Main -------------------- */
|
||||
|
||||
func main() {
|
||||
wtf.Config = Config
|
||||
|
||||
bamboohr.Config = Config
|
||||
bamboo := bamboohr.NewWidget()
|
||||
|
@ -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
47
wtf/text_widget.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user