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)
|
settings := ipapi.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = ipapi.NewWidget(app, settings)
|
widget = ipapi.NewWidget(app, settings)
|
||||||
case "ipinfo":
|
case "ipinfo":
|
||||||
widget = ipinfo.NewWidget(app)
|
settings := ipinfo.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = ipinfo.NewWidget(app, settings)
|
||||||
case "jenkins":
|
case "jenkins":
|
||||||
widget = jenkins.NewWidget(app, pages)
|
widget = jenkins.NewWidget(app, pages)
|
||||||
case "jira":
|
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 {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
result string
|
result string
|
||||||
colors struct {
|
settings *Settings
|
||||||
name, value string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ipinfo struct {
|
type ipinfo struct {
|
||||||
@ -30,15 +29,15 @@ type ipinfo struct {
|
|||||||
Organization string `json:"org"`
|
Organization string `json:"org"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "IPInfo", "ipinfo", false),
|
TextWidget: wtf.NewTextWidget(app, "IPInfo", "ipinfo", false),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetWrap(false)
|
widget.View.SetWrap(false)
|
||||||
|
|
||||||
widget.config()
|
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +74,6 @@ func (widget *Widget) ipinfo() {
|
|||||||
widget.setResult(&info)
|
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) {
|
func (widget *Widget) setResult(info *ipinfo) {
|
||||||
resultTemplate, _ := template.New("ipinfo_result").Parse(
|
resultTemplate, _ := template.New("ipinfo_result").Parse(
|
||||||
formatableText("IP", "Ip") +
|
formatableText("IP", "Ip") +
|
||||||
@ -95,8 +88,8 @@ func (widget *Widget) setResult(info *ipinfo) {
|
|||||||
resultBuffer := new(bytes.Buffer)
|
resultBuffer := new(bytes.Buffer)
|
||||||
|
|
||||||
resultTemplate.Execute(resultBuffer, map[string]string{
|
resultTemplate.Execute(resultBuffer, map[string]string{
|
||||||
"nameColor": widget.colors.name,
|
"nameColor": widget.settings.colors.name,
|
||||||
"valueColor": widget.colors.value,
|
"valueColor": widget.settings.colors.value,
|
||||||
"Ip": info.Ip,
|
"Ip": info.Ip,
|
||||||
"Hostname": info.Hostname,
|
"Hostname": info.Hostname,
|
||||||
"City": info.City,
|
"City": info.City,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user