diff --git a/main.go b/main.go index cef1dd01..031b7643 100644 --- a/main.go +++ b/main.go @@ -232,7 +232,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w settings := hackernews.NewSettingsFromYAML(wtf.Config) widget = hackernews.NewWidget(app, pages, settings) case "ipapi": - widget = ipapi.NewWidget(app) + settings := ipapi.NewSettingsFromYAML(wtf.Config) + widget = ipapi.NewWidget(app, settings) case "ipinfo": widget = ipinfo.NewWidget(app) case "jenkins": diff --git a/modules/ipaddresses/ipapi/settings.go b/modules/ipaddresses/ipapi/settings.go new file mode 100644 index 00000000..a78af00c --- /dev/null +++ b/modules/ipaddresses/ipapi/settings.go @@ -0,0 +1,29 @@ +package ipapi + +import ( + "github.com/olebedev/config" + "github.com/wtfutil/wtf/cfg" +) + +type colors struct { + name string + value string +} + +type Settings struct { + colors + common *cfg.Common +} + +func NewSettingsFromYAML(ymlConfig *config.Config) *Settings { + localConfig, _ := ymlConfig.Get("wtf.mods.ipapi") + + settings := Settings{ + common: cfg.NewCommonSettingsFromYAML(ymlConfig), + } + + settings.colors.name = localConfig.UString("colors.name", "red") + settings.colors.value = localConfig.UString("colors.value", "white") + + return &settings +} diff --git a/modules/ipaddresses/ipapi/widget.go b/modules/ipaddresses/ipapi/widget.go index 8a9bfc48..53dec853 100644 --- a/modules/ipaddresses/ipapi/widget.go +++ b/modules/ipaddresses/ipapi/widget.go @@ -15,10 +15,9 @@ import ( // Widget widget struct type Widget struct { wtf.TextWidget - result string - colors struct { - name, value string - } + + result string + settings *Settings } type ipinfo struct { @@ -37,15 +36,15 @@ type ipinfo struct { } // NewWidget constructor -func NewWidget(app *tview.Application) *Widget { +func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, "IPInfo", "ipapi", false), + + settings: settings, } widget.View.SetWrap(false) - widget.config() - return &widget } @@ -80,13 +79,6 @@ func (widget *Widget) ipinfo() { widget.setResult(&info) } -// read module configs -func (widget *Widget) config() { - nameColor, valueColor := wtf.Config.UString("wtf.mods.ipinfo.colors.name", "red"), wtf.Config.UString("wtf.mods.ipinfo.colors.value", "white") - widget.colors.name = nameColor - widget.colors.value = valueColor -} - func (widget *Widget) setResult(info *ipinfo) { resultTemplate, _ := template.New("ipinfo_result").Parse( formatableText("IP Address", "Ip") + @@ -104,8 +96,8 @@ func (widget *Widget) setResult(info *ipinfo) { resultBuffer := new(bytes.Buffer) resultTemplate.Execute(resultBuffer, map[string]string{ - "nameColor": widget.colors.name, - "valueColor": widget.colors.value, + "nameColor": widget.settings.colors.name, + "valueColor": widget.settings.colors.value, "Ip": info.Query, "ISP": info.ISP, "AS": info.AS,