mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Removed a bunch of common boilerplate code from widget initialization
This commit is contained in:
committed by
Chris Cummer
parent
d812986abc
commit
693a04b5e1
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user