mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 IPInfo extracted to new config format
This commit is contained in:
parent
0b6a589827
commit
d4558f533a
3
main.go
3
main.go
@ -235,7 +235,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
settings := ipapi.NewSettingsFromYAML(wtf.Config)
|
||||
widget = ipapi.NewWidget(app, settings)
|
||||
case "ipinfo":
|
||||
widget = ipinfo.NewWidget(app)
|
||||
settings := ipinfo.NewSettingsFromYAML(wtf.Config)
|
||||
widget = ipinfo.NewWidget(app, settings)
|
||||
case "jenkins":
|
||||
widget = jenkins.NewWidget(app, pages)
|
||||
case "jira":
|
||||
|
29
modules/ipaddresses/ipinfo/settings.go
Normal file
29
modules/ipaddresses/ipinfo/settings.go
Normal file
@ -0,0 +1,29 @@
|
||||
package ipinfo
|
||||
|
||||
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.ipinfo")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
}
|
||||
|
||||
settings.colors.name = localConfig.UString("colors.name", "red")
|
||||
settings.colors.value = localConfig.UString("colors.value", "white")
|
||||
|
||||
return &settings
|
||||
}
|
@ -13,10 +13,9 @@ import (
|
||||
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
result string
|
||||
colors struct {
|
||||
name, value string
|
||||
}
|
||||
|
||||
result string
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
type ipinfo struct {
|
||||
@ -30,15 +29,15 @@ type ipinfo struct {
|
||||
Organization string `json:"org"`
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "IPInfo", "ipinfo", false),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
widget.config()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@ -75,12 +74,6 @@ func (widget *Widget) ipinfo() {
|
||||
widget.setResult(&info)
|
||||
}
|
||||
|
||||
// read module configs
|
||||
func (widget *Widget) config() {
|
||||
widget.colors.name = wtf.Config.UString("wtf.mods.ipinfo.colors.name", "white")
|
||||
widget.colors.value = wtf.Config.UString("wtf.mods.ipinfo.colors.value", "white")
|
||||
}
|
||||
|
||||
func (widget *Widget) setResult(info *ipinfo) {
|
||||
resultTemplate, _ := template.New("ipinfo_result").Parse(
|
||||
formatableText("IP", "Ip") +
|
||||
@ -95,8 +88,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.Ip,
|
||||
"Hostname": info.Hostname,
|
||||
"City": info.City,
|
||||
|
Loading…
x
Reference in New Issue
Block a user