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

Properly scope Config to the wtf package and remove it as a dependency from everywhere else

This commit is contained in:
Chris Cummer
2018-06-16 14:59:22 -07:00
parent abedee0ce0
commit 66b69471d0
42 changed files with 126 additions and 251 deletions

View File

@@ -6,13 +6,9 @@ import (
"net/http"
"strings"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object
var Config *config.Config
type Widget struct {
wtf.TextWidget
result string
@@ -39,9 +35,9 @@ func (widget *Widget) Refresh() {
//this method reads the config and calls wttr.in for pretty weather
func (widget *Widget) prettyWeather() {
client := &http.Client{}
widget.unit = Config.UString("wtf.mods.prettyweather.unit", "m")
widget.city = Config.UString("wtf.mods.prettyweather.city", "")
widget.view = Config.UString("wtf.mods.prettyweather.view", "0")
widget.unit = wtf.Config.UString("wtf.mods.prettyweather.unit", "m")
widget.city = wtf.Config.UString("wtf.mods.prettyweather.city", "")
widget.view = wtf.Config.UString("wtf.mods.prettyweather.view", "0")
req, err := http.NewRequest("GET", "https://wttr.in/"+widget.city+"?"+widget.view+"?"+widget.unit, nil)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())

View File

@@ -55,14 +55,14 @@ func (widget *Widget) sunInfo(cityData *owm.CurrentWeatherData) string {
}
func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string {
tempUnit := Config.UString("wtf.mods.weather.tempUnit", "C")
tempUnit := wtf.Config.UString("wtf.mods.weather.tempUnit", "C")
str := fmt.Sprintf("%8s: %4.1f° %s\n", "High", cityData.Main.TempMax, tempUnit)
str = str + fmt.Sprintf(
"%8s: [%s]%4.1f° %s[white]\n",
"Current",
Config.UString("wtf.mods.weather.colors.current", "green"),
wtf.Config.UString("wtf.mods.weather.colors.current", "green"),
cityData.Main.Temp,
tempUnit,
)

View File

@@ -5,14 +5,10 @@ import (
owm "github.com/briandowns/openweathermap"
"github.com/gdamore/tcell"
"github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object.
var Config *config.Config
const HelpText = `
Keyboard commands for Weather:
@@ -75,7 +71,7 @@ func (widget *Widget) Fetch(cityIDs []int) []*owm.CurrentWeatherData {
// widget's view for rendering
func (widget *Widget) Refresh() {
if widget.apiKeyValid() {
widget.Data = widget.Fetch(wtf.ToInts(Config.UList("wtf.mods.weather.cityids", widget.defaultCityCodes())))
widget.Data = widget.Fetch(wtf.ToInts(wtf.Config.UList("wtf.mods.weather.cityids", widget.defaultCityCodes())))
}
widget.UpdateRefreshedAt()
@@ -131,7 +127,11 @@ func (widget *Widget) currentData() *owm.CurrentWeatherData {
}
func (widget *Widget) currentWeather(apiKey string, cityCode int) (*owm.CurrentWeatherData, error) {
weather, err := owm.NewCurrent(Config.UString("wtf.mods.weather.tempUnit", "C"), Config.UString("wtf.mods.weather.language", "EN"), apiKey)
weather, err := owm.NewCurrent(
wtf.Config.UString("wtf.mods.weather.tempUnit", "C"),
wtf.Config.UString("wtf.mods.weather.language", "EN"),
apiKey,
)
if err != nil {
return nil, err
}