Skip to content

Commit

Permalink
refactor: beautify the output format.
Browse files Browse the repository at this point in the history
  • Loading branch information
peanut996 committed Nov 9, 2023
1 parent 34f87b4 commit 524dd80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion task/warping.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
defaultPingTimes = 10
udpConnectTimeout = time.Millisecond * 1000
wireguardHandshakeRespBytes = 92
quickModeMaxIpNum = 5000
quickModeMaxIpNum = 100
warpPublicKey = "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo="
)

Expand Down
19 changes: 6 additions & 13 deletions utils/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,15 @@ func (s PingDelaySet) Print() {
fmt.Println("\n[Info] The total number of IP addresses in the complete speed test results is 0, so skipping the output.")
return
}
dateString := convertToString(s) // 转为多维数组 [][]String
if len(dateString) < PrintNum { // 如果IP数组长度(IP数量) 小于 打印次数,则次数改为IP数量
PrintNum = len(dateString)
}
headFormat := "%-16s%-5s%-6s\n"
dataFormat := "%-18s%-8s%-10s\n"
for i := 0; i < PrintNum; i++ { // 如果要输出的 IP 中包含 IPv6,那么就需要调整一下间隔
if len(dateString[i][0]) > 15 {
headFormat = "%-40s%-5s%-6s\n"
dataFormat = "%-42s%-8s%-10s\n"
break
}
dataString := convertToString(s) // 转为多维数组 [][]String
if len(dataString) < PrintNum { // 如果IP数组长度(IP数量) 小于 打印次数,则次数改为IP数量
PrintNum = len(dataString)
}
headFormat := "\n%-24s%-9s%-10s\n"
dataFormat := "%-25s%-8s%-10s\n"
fmt.Printf(headFormat, "IP:Port", "Loss", "Latency")
for i := 0; i < PrintNum; i++ {
fmt.Printf(dataFormat, dateString[i][0], dateString[i][1], dateString[i][2])
fmt.Printf(dataFormat, dataString[i][0], dataString[i][1], dataString[i][2])
}
if !noOutput() {
fmt.Printf("\nComplete speed test results have been written to the %v file.\n", Output)
Expand Down

0 comments on commit 524dd80

Please sign in to comment.