Browse Source

fix `-p=0` don't print result bug

mz 3 years ago
parent
commit
272eb40d5b
2 changed files with 10 additions and 0 deletions
  1. 3 0
      main.go
  2. 7 0
      utils/csv.go

+ 3 - 0
main.go

@@ -119,6 +119,9 @@ func main() {
 }
 
 func endPrint() {
+	if utils.NoPrintResult() {
+		return
+	}
 	if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
 		fmt.Println("\n按下 回车键 或 Ctrl+C 退出。")
 		var pause int

+ 7 - 0
utils/csv.go

@@ -23,6 +23,10 @@ var (
 	PrintNum      = 10
 )
 
+func NoPrintResult() bool {
+	return PrintNum == 0
+}
+
 type PingData struct {
 	IP       *net.IPAddr
 	Sended   int
@@ -132,6 +136,9 @@ func (s DownloadSpeedSet) Swap(i, j int) {
 }
 
 func (s DownloadSpeedSet) Print(ipv6 bool) {
+	if NoPrintResult() {
+		return
+	}
 	if len(s) <= 0 { // IP数组长度(IP数量) 大于 0 时继续
 		fmt.Println("\n[信息] 完整测速结果 IP 数量为 0,跳过输出结果。")
 		return