From 693a04b5e11f934c600b29964a78bc45b64edb3c Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 15 Apr 2018 13:05:28 -0700 Subject: [PATCH] Removed a bunch of common boilerplate code from widget initialization --- .DS_Store | Bin 6148 -> 6148 bytes _site/config.toml | 2 +- bamboohr/widget.go | 16 ----- color/colors.go | 155 +++++++++++++++++++++++++++++++++++++++++++++ gcal/widget.go | 16 ----- git/widget.go | 16 ----- github/widget.go | 16 ----- jira/widget.go | 15 ----- newrelic/widget.go | 16 ----- opsgenie/widget.go | 16 ----- security/widget.go | 16 ----- status/widget.go | 16 ----- weather/widget.go | 18 +----- wtf/text_widget.go | 15 +++++ 14 files changed, 173 insertions(+), 160 deletions(-) create mode 100644 color/colors.go diff --git a/.DS_Store b/.DS_Store index 0e4324dad2dcd52cfef04182b6b46b7f4a37bf58..f996d77e7d4e5af59a39e27eca2959e51e263dd6 100644 GIT binary patch delta 43 zcmZoMXfc=&!NrhT7F?8Pua3>X65+L4* 0 { str := "" diff --git a/jira/widget.go b/jira/widget.go index 8abe65d1..633393eb 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -4,9 +4,7 @@ import ( "fmt" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) @@ -21,8 +19,6 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget("JIRA", "jira"), } - widget.addView() - return &widget } @@ -58,17 +54,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - - widget.View = view -} - func (widget *Widget) contentFrom(searchResult *SearchResult) string { str := " [red]Assigned Issues[white]\n" diff --git a/newrelic/widget.go b/newrelic/widget.go index 2a1bce1c..c94e53a2 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -4,9 +4,7 @@ import ( "fmt" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" nr "github.com/yfronto/newrelic" ) @@ -22,8 +20,6 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget(" New Relic ", "newrelic"), } - widget.addView() - return &widget } @@ -59,18 +55,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - view.SetWrap(false) - - widget.View = view -} - func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { str := fmt.Sprintf( " %s\n", diff --git a/opsgenie/widget.go b/opsgenie/widget.go index 051518bf..1b7f7dd5 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -5,9 +5,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) @@ -22,8 +20,6 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget(" ⏰ OpsGenie ", "opsgenie"), } - widget.addView() - return &widget } @@ -53,18 +49,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - view.SetWrap(false) - - widget.View = view -} - func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string { str := "" diff --git a/security/widget.go b/security/widget.go index 69d1fe10..36f2f34b 100644 --- a/security/widget.go +++ b/security/widget.go @@ -4,9 +4,7 @@ import ( "fmt" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) @@ -21,8 +19,6 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget(" ðŸĪš Security ", "security"), } - widget.addView() - return &widget } @@ -44,18 +40,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - view.SetWrap(false) - - widget.View = view -} - func (widget *Widget) contentFrom(data *SecurityData) string { str := " [red]WiFi[white]\n" diff --git a/status/widget.go b/status/widget.go index a526b456..5ba66cf3 100644 --- a/status/widget.go +++ b/status/widget.go @@ -5,9 +5,7 @@ import ( "strings" "time" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) @@ -25,8 +23,6 @@ func NewWidget() *Widget { Current: 0, } - widget.addView() - return &widget } @@ -52,18 +48,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - view.SetWrap(false) - - widget.View = view -} - func (widget *Widget) animation() string { icons := []string{"👍", "ðŸĪœ", "ðŸĪ™", "ðŸĪœ", "ðŸĪ˜", "ðŸĪœ", "✊", "ðŸĪœ", "👌", "ðŸĪœ"} next := icons[widget.Current] diff --git a/weather/widget.go b/weather/widget.go index 107794d8..400d5768 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -6,9 +6,7 @@ import ( "time" owm "github.com/briandowns/openweathermap" - "github.com/gdamore/tcell" "github.com/olebedev/config" - "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) @@ -23,8 +21,6 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget(" Weather ", "weather"), } - widget.addView() - return &widget } @@ -47,18 +43,6 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ -func (widget *Widget) addView() { - view := tview.NewTextView() - - view.SetBorder(true) - view.SetBorderColor(tcell.ColorGray) - view.SetDynamicColors(true) - view.SetTitle(widget.Name) - view.SetWrap(false) - - widget.View = view -} - func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string { if len(data.Weather) == 0 { return " Weather data is unavailable." @@ -138,6 +122,8 @@ func icon(data *owm.CurrentWeatherData) string { icon = "ðŸŒĪ" case "scattered clouds": icon = "☁ïļ" + case "shower rain": + icon = "☔ïļ" case "snow": icon = "❄ïļ" case "sunny": diff --git a/wtf/text_widget.go b/wtf/text_widget.go index f2fceda7..606c04e8 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -6,6 +6,7 @@ import ( "github.com/olebedev/config" "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/color" ) var Config *config.Config @@ -34,9 +35,23 @@ func NewTextWidget(name string, configKey string) TextWidget { }, } + widget.addView() + return widget } +func (widget *TextWidget) addView() { + view := tview.NewTextView() + + view.SetBorder(true) + view.SetBorderColor(color.ColorFor(Config.UString("wtf.border.normal"))) + view.SetDynamicColors(true) + view.SetTitle(widget.Name) + view.SetWrap(false) + + widget.View = view +} + /* -------------------- Exported Functions -------------------- */ func (widget *TextWidget) Disabled() bool {