1
- use colorful:: { Color , Colorful } ;
2
-
3
1
use crate :: {
4
2
models:: types:: {
5
3
PerformIcmpResponseNodeInfo , PerformIcmpResponseResultsItem ,
6
4
PerformIcmpResponseResultsItemResult ,
7
5
} ,
8
6
options:: Opts ,
9
7
} ;
8
+ use colorful:: { Color , Colorful } ;
10
9
use std:: * ;
11
10
12
- /*
13
- * PING bitping.com (76.76.21.21): 56 data bytes
14
- 64 bytes from 76.76.21.21: icmp_seq=0 ttl=120 time=16.181 ms
15
- 64 bytes from 76.76.21.21: icmp_seq=1 ttl=120 time=10.129 ms
16
- 64 bytes from 76.76.21.21: icmp_seq=2 ttl=120 time=15.644 ms
17
- ^C
18
- --- bitping.com ping statistics ---
19
- 4 packets transmitted, 4 packets received, 0.0% packet loss
20
- round-trip min/avg/max/stddev = 10.127/13.020/16.181/2.898 ms
21
- *
22
- */
11
+ fn print_border ( pb : & indicatif:: ProgressBar , width : usize ) {
12
+ pb. println ( "┌" . to_string ( ) + & "─" . repeat ( width - 2 ) + "┐" ) ;
13
+ }
14
+
15
+ fn print_footer ( pb : & indicatif:: ProgressBar , width : usize ) {
16
+ pb. println ( "└" . to_string ( ) + & "─" . repeat ( width - 2 ) + "┘" ) ;
17
+ }
18
+
23
19
pub fn display_success_ping (
24
20
pb : & indicatif:: ProgressBar ,
25
21
config : & Opts ,
26
22
endpoint : & str ,
27
23
jobres : & PerformIcmpResponseResultsItemResult ,
28
24
node_info : & PerformIcmpResponseNodeInfo ,
29
25
) {
26
+ let width = 80 ; // Adjust this value as needed
27
+ print_border ( pb, width) ;
30
28
format_ping_header ( pb, config, endpoint, & jobres. ip_address , node_info) ;
31
29
32
30
// Display individual ping results
33
31
let trips = jobres. trips as usize ;
34
32
for i in 0 ..trips {
35
33
let time = jobres. min + ( jobres. max - jobres. min ) * ( i as f64 / ( trips - 1 ) as f64 ) ;
36
34
pb. println ( format ! (
37
- "64 bytes from {}: icmp_seq={} ttl=120 time={:.2} ms" ,
35
+ "│ 64 bytes from {}: icmp_seq={} ttl=120 time={:.2} ms" ,
38
36
jobres. ip_address, i, time
39
37
) ) ;
40
38
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
41
39
}
42
40
43
- pb. println ( "" ) ; // Empty line for spacing
41
+ pb. println ( "│ " ) ; // Empty line for spacing
44
42
45
43
// Construct and print statistics line
46
- pb. println ( format ! ( "--- {endpoint} ping statistics ---" ) ) ;
44
+ pb. println ( format ! ( "│ --- {endpoint} ping statistics ---" ) ) ;
47
45
48
46
// Print packet loss information
49
47
pb. println ( format ! (
50
- "{} packets transmitted, {} packets received, {:.1}% packet loss" ,
48
+ "│ {} packets transmitted, {} packets received, {:.1}% packet loss" ,
51
49
jobres. packets_sent,
52
50
jobres. packets_recv,
53
51
jobres. packet_loss * 100.0
54
52
) ) ;
55
53
56
54
// Print round-trip statistics
57
55
pb. println ( format ! (
58
- "round-trip min/avg/max/stddev = {:.3}/{:.3}/{:.3}/{:.3} ms" ,
56
+ "│ round-trip min/avg/max/stddev = {:.3}/{:.3}/{:.3}/{:.3} ms" ,
59
57
jobres. min, jobres. avg, jobres. max, jobres. std_dev
60
58
) ) ;
59
+
60
+ print_footer ( pb, width) ;
61
61
}
62
62
63
- /*
64
- * PING asdasdasd.com (199.59.242.153): 56 data bytes
65
- Request timeout for icmp_seq 0
66
- Request timeout for icmp_seq 1
67
- Request timeout for icmp_seq 2
68
- Request timeout for icmp_seq 3
69
- ^C
70
- --- asdasdasd.com ping statistics ---
71
- 5 packets transmitted, 0 packets received, 100.0% packet loss
72
- */
73
63
pub fn display_failed_ping (
74
64
pb : & indicatif:: ProgressBar ,
75
65
config : & Opts ,
76
66
jobres : & PerformIcmpResponseResultsItem ,
77
67
node_info : & PerformIcmpResponseNodeInfo ,
78
68
) {
69
+ let width = 80 ; // Adjust this value as needed
70
+ print_border ( pb, width) ;
79
71
let ip_address = jobres
80
72
. result
81
73
. as_ref ( )
@@ -85,28 +77,30 @@ pub fn display_failed_ping(
85
77
// Request timeout for icmp_seq 0, 1, 2, 3
86
78
let attempts = jobres. result . as_ref ( ) . map_or ( 4 , |r| r. attempts as usize ) ;
87
79
for index in 0 ..attempts {
88
- pb. println ( format ! ( "Request timeout for icmp_seq {}" , index) ) ;
80
+ pb. println ( format ! ( "│ Request timeout for icmp_seq {}" , index) ) ;
89
81
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
90
82
}
91
83
92
84
// --- asdasdasd.com ping statistics ---
93
- pb. println ( format ! ( "--- {} ping statistics ---" , jobres. endpoint) ) ;
85
+ pb. println ( format ! ( "│ --- {} ping statistics ---" , jobres. endpoint) ) ;
94
86
95
87
// 5 packets transmitted, 0 packets received, 100.0% packet loss
96
88
let error_string = if let Some ( result) = & jobres. result {
97
89
format ! (
98
- "{} packets transmitted, {} packets received, {:.1}% packet loss" ,
90
+ "│ {} packets transmitted, {} packets received, {:.1}% packet loss" ,
99
91
result. packets_sent,
100
92
result. packets_recv,
101
93
result. packet_loss * 100.0
102
94
)
103
95
} else {
104
96
format ! (
105
- "{} packets transmitted, 0 packets received, 100% packet loss" ,
97
+ "│ {} packets transmitted, 0 packets received, 100% packet loss" ,
106
98
attempts
107
99
)
108
100
} ;
109
101
pb. println ( format ! ( "{}" , error_string. color( Color :: Red ) ) ) ;
102
+
103
+ print_footer ( pb, width) ;
110
104
}
111
105
112
106
pub fn format_ping_header (
@@ -117,7 +111,7 @@ pub fn format_ping_header(
117
111
node_info : & PerformIcmpResponseNodeInfo ,
118
112
) {
119
113
// PING line
120
- let ping_line = format ! ( "PING {} ({}): 56 data bytes" , endpoint, ip_address) ;
114
+ let ping_line = format ! ( "│ PING {} ({}): 56 data bytes" , endpoint, ip_address) ;
121
115
pb. println ( ping_line) ;
122
116
123
117
// Origin line
@@ -138,7 +132,7 @@ pub fn format_ping_header(
138
132
} ;
139
133
140
134
let origin_line = format ! (
141
- "├── Origin: {} {}, {} {}" ,
135
+ "│ ├── Origin: {} {}, {} {}" ,
142
136
country_emoji. unwrap_or( "" ) ,
143
137
node_info. region_name. as_deref( ) . unwrap_or( "Unknown" ) ,
144
138
country_name,
@@ -147,16 +141,19 @@ pub fn format_ping_header(
147
141
pb. println ( origin_line) ;
148
142
149
143
// ISP line
150
- let isp_line = format ! ( "├── ISP: {}" , node_info. isp. as_deref( ) . unwrap_or( "Unknown" ) ) ;
144
+ let isp_line = format ! (
145
+ "│ ├── ISP: {}" ,
146
+ node_info. isp. as_deref( ) . unwrap_or( "Unknown" )
147
+ ) ;
151
148
pb. println ( isp_line) ;
152
149
153
150
// System line
154
151
let system_line = format ! (
155
- "└── System: {}" ,
152
+ "│ └── System: {}" ,
156
153
node_info. operating_system. as_deref( ) . unwrap_or( "Unknown" )
157
154
) ;
158
155
pb. println ( system_line) ;
159
156
160
157
// Separator line
161
- pb. println ( "---" ) ;
158
+ pb. println ( "│ ---" ) ;
162
159
}
0 commit comments