Skip to content

Commit d2539a2

Browse files
committed
add formatted in one line print output. change External IP and Local interface name lines to colored.
1 parent 4e29ca6 commit d2539a2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module github.com/iqhater/myip
22

33
go 1.21
4+
5+
require github.com/fatih/color v1.17.0
6+
7+
require (
8+
github.com/mattn/go-colorable v0.1.13 // indirect
9+
github.com/mattn/go-isatty v0.0.20 // indirect
10+
golang.org/x/sys v0.18.0 // indirect
11+
)

go.sum

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
2+
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
3+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
4+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
5+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
6+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
7+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
8+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
11+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

view/ui.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77

8+
"github.com/fatih/color"
89
"github.com/iqhater/myip/data"
910
)
1011

@@ -13,26 +14,26 @@ var out io.Writer = os.Stdout
1314

1415
// PrintInternal print all internal ip data
1516
func PrintInternal(d *data.IPData) {
16-
fmt.Fprintln(out, "Local interface name:", d.AdapterName)
17-
fmt.Fprintln(out, "Internal IP:", d.IntIP)
17+
color.New(color.FgMagenta).Fprintln(out, "Local interface name:", d.AdapterName)
18+
fmt.Fprintln(out, " Internal IP:", d.IntIP)
1819
}
1920

2021
// PrintExternal print all external ip data
2122
func PrintExternal(d *data.IPData) {
2223

2324
if d.ExtIP != "" {
24-
fmt.Fprintln(out, "External IP:", d.ExtIP)
25+
color.New(color.FgGreen).Fprintln(out, " External IP:", d.ExtIP)
2526
}
2627

2728
if d.Country != "" {
28-
fmt.Fprintln(out, "Country:", d.Country)
29+
fmt.Fprintln(out, " Country:", d.Country)
2930
}
3031

3132
if d.CountryCode != "" {
32-
fmt.Fprintln(out, "Country Code:", d.CountryCode)
33+
fmt.Fprintln(out, " Country Code:", d.CountryCode)
3334
}
3435

3536
if d.Region != "" {
36-
fmt.Fprintln(out, "Region:", d.Region)
37+
fmt.Fprintln(out, " Region:", d.Region)
3738
}
3839
}

0 commit comments

Comments
 (0)