mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Simplify the inclusion of the Common config settings into each module
Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
@@ -11,15 +11,18 @@ const (
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
city string
|
||||
*cfg.Common
|
||||
|
||||
city string
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
city: ymlConfig.UString("locationid"),
|
||||
}
|
||||
|
||||
settings.SetDocumentationPath("weather_services/arpansagovau")
|
||||
|
||||
return &settings
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type Widget struct {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
locationData, err := GetLocationData(settings.city)
|
||||
widget := Widget{
|
||||
TextWidget: view.NewTextWidget(app, nil, settings.common),
|
||||
TextWidget: view.NewTextWidget(app, nil, settings.Common),
|
||||
|
||||
location: locationData,
|
||||
lastError: err,
|
||||
|
||||
@@ -11,7 +11,7 @@ const (
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
*cfg.Common
|
||||
|
||||
city string
|
||||
unit string
|
||||
@@ -21,7 +21,7 @@ type Settings struct {
|
||||
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
|
||||
city: ymlConfig.UString("city", "Barcelona"),
|
||||
language: ymlConfig.UString("language", "en"),
|
||||
@@ -29,5 +29,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
view: ymlConfig.UString("view", "0"),
|
||||
}
|
||||
|
||||
settings.SetDocumentationPath("weather_services/prettyweather")
|
||||
|
||||
return &settings
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: view.NewTextWidget(app, nil, settings.common),
|
||||
TextWidget: view.NewTextWidget(app, nil, settings.Common),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (widget *Widget) content() (string, string, bool) {
|
||||
} else {
|
||||
title = widget.buildTitle(cityData)
|
||||
_, _, width, _ := widget.View.GetRect()
|
||||
content = widget.settings.common.PaginationMarker(len(widget.Data), widget.Idx, width) + "\n"
|
||||
content = widget.settings.PaginationMarker(len(widget.Data), widget.Idx, width) + "\n"
|
||||
content += widget.description(cityData) + "\n\n"
|
||||
content += widget.temperatures(cityData) + "\n"
|
||||
content += widget.sunInfo(cityData)
|
||||
|
||||
@@ -18,7 +18,7 @@ type colors struct {
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
*cfg.Common
|
||||
|
||||
apiKey string
|
||||
cityIDs []interface{}
|
||||
@@ -29,7 +29,7 @@ type Settings struct {
|
||||
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_OWM_API_KEY"))),
|
||||
cityIDs: ymlConfig.UList("cityids"),
|
||||
@@ -38,6 +38,8 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
useEmoji: ymlConfig.UBool("useEmoji", true),
|
||||
}
|
||||
|
||||
settings.SetDocumentationPath("weather_services/weather/")
|
||||
|
||||
settings.colors.current = ymlConfig.UString("colors.current", "green")
|
||||
|
||||
return &settings
|
||||
|
||||
@@ -22,8 +22,8 @@ type Widget struct {
|
||||
// NewWidget creates and returns a new instance of the weather Widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "cityid", "cityids"),
|
||||
TextWidget: view.NewTextWidget(app, pages, settings.common),
|
||||
MultiSourceWidget: view.NewMultiSourceWidget(settings.Common, "cityid", "cityids"),
|
||||
TextWidget: view.NewTextWidget(app, pages, settings.Common),
|
||||
|
||||
pages: pages,
|
||||
settings: settings,
|
||||
|
||||
Reference in New Issue
Block a user