mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'jeangovil-c-ipinfo'
This commit is contained in:
commit
61c8022651
@ -26,6 +26,9 @@ None.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
ipinfo:
|
ipinfo:
|
||||||
|
colors:
|
||||||
|
name: red
|
||||||
|
value: white
|
||||||
enabled: true
|
enabled: true
|
||||||
position:
|
position:
|
||||||
top: 1
|
top: 1
|
||||||
@ -37,6 +40,14 @@ ipinfo:
|
|||||||
|
|
||||||
### Attributes
|
### Attributes
|
||||||
|
|
||||||
|
`colors.name` <br />
|
||||||
|
The default colour for the row names. <br />
|
||||||
|
Values: Any <a href="https://en.wikipedia.org/wiki/X11_color_names">X11 color</a> name.
|
||||||
|
|
||||||
|
`colors.value` <br />
|
||||||
|
The default colour for the row values. <br />
|
||||||
|
Values: Any <a href="https://en.wikipedia.org/wiki/X11_color_names">X11 color</a> name.
|
||||||
|
|
||||||
`enabled` <br />
|
`enabled` <br />
|
||||||
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
||||||
Values: `true`, `false`.
|
Values: `true`, `false`.
|
||||||
|
@ -36,8 +36,10 @@ position Defines where in the grid this module&rsquo;s widget will be displa
|
|||||||
<description>Displays your current IP address information, from ipinfo.io.
|
<description>Displays your current IP address information, from ipinfo.io.
|
||||||
Source Code wtf/ipinfo/ Required ENV Variables None.
|
Source Code wtf/ipinfo/ Required ENV Variables None.
|
||||||
Keyboard Commands None.
|
Keyboard Commands None.
|
||||||
Configuration ipinfo:enabled:trueposition:top:1left:2height:1width:1refreshInterval:15 Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Configuration ipinfo:colors:name:redvalue:whiteenabled:trueposition:top:1left:2height:1width:1refreshInterval:15 Attributes colors.name The default colour for the row names. Values: Any X11 color name.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed. refreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0..n.</description>
|
colors.value The default colour for the row values. Values: Any X11 color name.
|
||||||
|
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
||||||
|
position Defines where in the grid this module&rsquo;s widget will be displayed.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -36,8 +36,10 @@ position Defines where in the grid this module&rsquo;s widget will be displa
|
|||||||
<description>Displays your current IP address information, from ipinfo.io.
|
<description>Displays your current IP address information, from ipinfo.io.
|
||||||
Source Code wtf/ipinfo/ Required ENV Variables None.
|
Source Code wtf/ipinfo/ Required ENV Variables None.
|
||||||
Keyboard Commands None.
|
Keyboard Commands None.
|
||||||
Configuration ipinfo:enabled:trueposition:top:1left:2height:1width:1refreshInterval:15 Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
Configuration ipinfo:colors:name:redvalue:whiteenabled:trueposition:top:1left:2height:1width:1refreshInterval:15 Attributes colors.name The default colour for the row names. Values: Any X11 color name.
|
||||||
position Defines where in the grid this module&rsquo;s widget will be displayed. refreshInterval How often, in seconds, this module will update its data. Values: A positive integer, 0..n.</description>
|
colors.value The default colour for the row values. Values: Any X11 color name.
|
||||||
|
enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false.
|
||||||
|
position Defines where in the grid this module&rsquo;s widget will be displayed.</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
@ -127,6 +127,9 @@
|
|||||||
|
|
||||||
<h2 id="configuration">Configuration</h2>
|
<h2 id="configuration">Configuration</h2>
|
||||||
<div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">ipinfo<span class="p">:</span><span class="w">
|
<div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">ipinfo<span class="p">:</span><span class="w">
|
||||||
|
</span><span class="w"> </span>colors<span class="p">:</span><span class="w">
|
||||||
|
</span><span class="w"> </span>name<span class="p">:</span><span class="w"> </span>red<span class="w">
|
||||||
|
</span><span class="w"> </span>value<span class="p">:</span><span class="w"> </span>white<span class="w">
|
||||||
</span><span class="w"> </span>enabled<span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="w">
|
</span><span class="w"> </span>enabled<span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="w">
|
||||||
</span><span class="w"> </span>position<span class="p">:</span><span class="w">
|
</span><span class="w"> </span>position<span class="p">:</span><span class="w">
|
||||||
</span><span class="w"> </span>top<span class="p">:</span><span class="w"> </span><span class="m">1</span><span class="w">
|
</span><span class="w"> </span>top<span class="p">:</span><span class="w"> </span><span class="m">1</span><span class="w">
|
||||||
@ -136,6 +139,14 @@
|
|||||||
</span><span class="w"> </span>refreshInterval<span class="p">:</span><span class="w"> </span><span class="m">15</span></code></pre></div>
|
</span><span class="w"> </span>refreshInterval<span class="p">:</span><span class="w"> </span><span class="m">15</span></code></pre></div>
|
||||||
<h3 id="attributes">Attributes</h3>
|
<h3 id="attributes">Attributes</h3>
|
||||||
|
|
||||||
|
<p><code>colors.name</code> <br />
|
||||||
|
The default colour for the row names. <br />
|
||||||
|
Values: Any <a href="https://en.wikipedia.org/wiki/X11_color_names">X11 color</a> name.</p>
|
||||||
|
|
||||||
|
<p><code>colors.value</code> <br />
|
||||||
|
The default colour for the row values. <br />
|
||||||
|
Values: Any <a href="https://en.wikipedia.org/wiki/X11_color_names">X11 color</a> name.</p>
|
||||||
|
|
||||||
<p><code>enabled</code> <br />
|
<p><code>enabled</code> <br />
|
||||||
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
||||||
Values: <code>true</code>, <code>false</code>.</p>
|
Values: <code>true</code>, <code>false</code>.</p>
|
||||||
|
@ -3,9 +3,13 @@ package ipinfo
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"bytes"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is a pointer to the global config object
|
// Config is a pointer to the global config object
|
||||||
@ -14,6 +18,9 @@ var Config *config.Config
|
|||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
result string
|
result string
|
||||||
|
colors struct {
|
||||||
|
name, value string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ipinfo struct {
|
type ipinfo struct {
|
||||||
@ -29,11 +36,13 @@ type ipinfo struct {
|
|||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget("IPInfo", "ipinfo", false),
|
TextWidget: wtf.NewTextWidget(" IPInfo ", "ipinfo", false),
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
|
|
||||||
|
widget.config()
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +54,8 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
widget.ipinfo()
|
widget.ipinfo()
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
|
|
||||||
|
|
||||||
fmt.Fprintf(widget.View, "%s", widget.result)
|
widget.View.SetText(widget.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
//this method reads the config and calls ipinfo for ip information
|
//this method reads the config and calls ipinfo for ip information
|
||||||
@ -75,15 +83,47 @@ func (widget *Widget) ipinfo() {
|
|||||||
widget.result = fmt.Sprintf("%s", err.Error())
|
widget.result = fmt.Sprintf("%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
widget.result = fmt.Sprintf(
|
|
||||||
"[red]IP Address:[white] %s\n[red]Hostname:[white] %v\n[red]City:[white] %s\n[red]Region:[white] %s\n[red]Country:[white] %s\n[red]Coordinates:[white] %v\n[red]Postal Code:[white] %s\n[red]Organization:[white] %v",
|
widget.setResult(&info)
|
||||||
info.Ip,
|
}
|
||||||
info.Hostname,
|
|
||||||
info.City,
|
// read module configs
|
||||||
info.Region,
|
func (widget *Widget) config() {
|
||||||
info.Country,
|
nameColor, valueColor := Config.UString("wtf.mods.ipinfo.colors.name", "red"), Config.UString("wtf.mods.ipinfo.colors.value", "white")
|
||||||
info.Coordinates,
|
widget.colors.name = nameColor
|
||||||
info.PostalCode,
|
widget.colors.value = valueColor
|
||||||
info.Organization,
|
}
|
||||||
)
|
|
||||||
|
func (widget *Widget) setResult(info *ipinfo) {
|
||||||
|
resultTemplate, _ := template.New("ipinfo_result").Parse(
|
||||||
|
formatableText("IP Address", "Ip") +
|
||||||
|
formatableText("Hostname", "Hostname") +
|
||||||
|
formatableText("City", "City") +
|
||||||
|
formatableText("Region", "Region") +
|
||||||
|
formatableText("Country", "Country") +
|
||||||
|
formatableText("Coordinates", "Coordinates") +
|
||||||
|
formatableText("Postal Code", "PostalCode") +
|
||||||
|
formatableText("Organization", "Organization"),
|
||||||
|
)
|
||||||
|
|
||||||
|
resultBuffer := new(bytes.Buffer)
|
||||||
|
|
||||||
|
resultTemplate.Execute(resultBuffer, map[string]string{
|
||||||
|
"nameColor": widget.colors.name,
|
||||||
|
"valueColor": widget.colors.value,
|
||||||
|
"Ip": info.Ip,
|
||||||
|
"Hostname": info.Hostname,
|
||||||
|
"City": info.City,
|
||||||
|
"Region": info.Region,
|
||||||
|
"Country": info.Country,
|
||||||
|
"Coordinates": info.Coordinates,
|
||||||
|
"PostalCode": info.PostalCode,
|
||||||
|
"Organization": info.Organization,
|
||||||
|
})
|
||||||
|
|
||||||
|
widget.result = resultBuffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatableText(key, value string) string {
|
||||||
|
return fmt.Sprintf("[{{.nameColor}}]%s: [{{.valueColor}}]{{.%s}}\n", key, value)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user