Skip to content

Commit b8f075d

Browse files
committed
Update 1.5.0
1 parent e4b1534 commit b8f075d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,27 @@ type TitleValues struct {
3737
Baseboard string `json:"baseboard"`
3838
ProcessCount string `json:"processCount"`
3939
Uptime string `json:"uptime"`
40+
Network string `json:"network"`
4041
}
4142

4243
func updateConfig(config Config) {
4344
user, _ := user.Current()
4445
if config.Version == 0 {
4546
config.AutoUpdate = true
47+
config.Version = 1
48+
}
49+
if config.Version == 1 {
50+
config.Titles.Network = "Local IP"
51+
config.Format = append(config.Format, "network")
52+
config.Version = 2
4653
}
47-
config.Version = 1
4854
file, _ := json.MarshalIndent(config, "", " ")
4955
_ = ioutil.WriteFile(user.HomeDir+"\\.winfetch.json", file, 0644)
5056
}
5157

5258
func newConfig() Config {
5359
config := Config{}
54-
config.Format = []string{"user", "sep", "uptime", "mem", "cpu", "procs", "cpuCores", "cpuThreads", "disk", "wversion", "gpus", "bios", "baseboard"}
60+
config.Format = []string{"user", "sep", "uptime", "mem", "cpu", "procs", "cpuCores", "cpuThreads", "disk", "wversion", "gpus", "bios", "baseboard", "network"}
5561
config.ShowASCII = true
5662
config.UseSmallASCII = false
5763
config.UseCustomASCII = false
@@ -73,6 +79,7 @@ func newConfig() Config {
7379
config.Titles.Uptime = "Uptime"
7480
config.Titles.ProcessCount = "Processes"
7581
config.Titles.CPU = "CPU #"
82+
config.Titles.Network = "Local IP"
7683
config.AutoUpdate = true
7784
config.Version = 1
7885
return config

helpers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"math"
7+
"net"
78
"os/user"
89
"strconv"
910
"strings"
@@ -138,6 +139,9 @@ func generateInfo(config Config, title xterm256.Color, info xterm256.Color, user
138139
}
139140
for x := range config.Format {
140141
switch config.Format[x] {
142+
case "network":
143+
outboundIP := getOutboundIP()
144+
s = append(s, xterm256.Sprint(title, config.Titles.Network+": ")+xterm256.Sprint(info, outboundIP.String()))
141145
case "user":
142146
user, _ := user.Current()
143147
s = append(s, xterm256.Sprint(userc, strings.ReplaceAll(user.Username, "\\", "@")))
@@ -230,3 +234,15 @@ func generateInfo(config Config, title xterm256.Color, info xterm256.Color, user
230234
s = append(s, " "+xterm256.Sprint(xterm256.DarkGray, "███")+xterm256.Sprint(xterm256.DarkRed, "███")+xterm256.Sprint(xterm256.DarkGreen, "███")+xterm256.Sprint(xterm256.DarkYellow, "███")+xterm256.Sprint(xterm256.DarkBlue, "███")+xterm256.Sprint(xterm256.DarkMagenta, "███")+xterm256.Sprint(xterm256.DarkCyan, "███"))
231235
return s
232236
}
237+
238+
func getOutboundIP() net.IP {
239+
conn, err := net.Dial("udp", "8.8.8.8:80")
240+
if err != nil {
241+
log.Fatal(err)
242+
}
243+
defer conn.Close()
244+
245+
localAddr := conn.LocalAddr().(*net.UDPAddr)
246+
247+
return localAddr.IP
248+
}

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.5.0

0 commit comments

Comments
 (0)