@@ -213,6 +213,7 @@ static double opt_exit_status_threshold = 1.0;
213
213
#if USE_NCURSES
214
214
static int opt_show_graph = 1 ;
215
215
static int opt_utf8 = 0 ;
216
+ static int opt_box = 1 ;
216
217
#endif
217
218
static char * opt_outfile = NULL ;
218
219
static int opt_bell = 0 ;
@@ -471,6 +472,7 @@ static void usage_exit (const char *name, int status) /* {{{ */
471
472
#if USE_NCURSES
472
473
" -u / -U force / disable UTF-8 output\n"
473
474
" -g graph graph type to draw\n"
475
+ " -B don't draw boxes\n"
474
476
#endif
475
477
" -P percent Report the n'th percentile of latency\n"
476
478
" -Z percent Exit with non-zero exit status if more than this percentage of\n"
@@ -677,7 +679,7 @@ static int read_options (int argc, char **argv) /* {{{ */
677
679
678
680
while (1 )
679
681
{
680
- optchar = getopt (argc , argv , "46c :hi:I:t:Q:f:D:Z:O:P:m:w:b"
682
+ optchar = getopt (argc , argv , "46Bc :hi:I:t:Q:f:D:Z:O:P:m:w:b"
681
683
#if USE_NCURSES
682
684
"uUg:"
683
685
#endif
@@ -815,6 +817,10 @@ static int read_options (int argc, char **argv) /* {{{ */
815
817
case 'U' :
816
818
opt_utf8 = 1 ;
817
819
break ;
820
+
821
+ case 'B' :
822
+ opt_box = 0 ;
823
+ break ;
818
824
#endif
819
825
case 'b' :
820
826
opt_bell = 1 ;
@@ -918,7 +924,7 @@ static _Bool has_utf8() /* {{{ */
918
924
# endif
919
925
} /* }}} _Bool has_utf8 */
920
926
921
- static int update_graph_boxplot (ping_context_t * ctx ) /* {{{ */
927
+ static int update_graph_boxplot (ping_context_t * ctx , int graph_x , int graph_y ) /* {{{ */
922
928
{
923
929
uint32_t * counters ;
924
930
double * ratios ;
@@ -1011,8 +1017,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
1011
1017
1012
1018
if (reverse )
1013
1019
wattron (ctx -> window , A_REVERSE );
1014
- mvwaddch (ctx -> window , /* y = */ 3 , /* x = */ (int ) (x + 2 ), symbol );
1015
- // mvwprintw (ctx->window, /* y = */ 3 , /* x = */ (int) (x + 2 ), symbol);
1020
+ mvwaddch (ctx -> window , /* y = */ graph_y , /* x = */ (int ) (x + graph_x ), symbol );
1021
+ // mvwprintw (ctx->window, /* y = */ graph_y , /* x = */ (int) (x + graph_x ), symbol);
1016
1022
if (reverse )
1017
1023
wattroff (ctx -> window , A_REVERSE );
1018
1024
}
@@ -1022,7 +1028,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
1022
1028
return (0 );
1023
1029
} /* }}} int update_graph_boxplot */
1024
1030
1025
- static int update_graph_prettyping (ping_context_t * ctx , /* {{{ */
1031
+ static int update_graph_prettyping (ping_context_t * ctx , /* {{{ */
1032
+ int graph_x , int graph_y ,
1026
1033
double latency )
1027
1034
{
1028
1035
size_t x ;
@@ -1063,7 +1070,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
1063
1070
1064
1071
if (x >= ctx -> history_size )
1065
1072
{
1066
- mvwaddch (ctx -> window , /* y = */ 3 , /* x = */ x + 2 , ' ' );
1073
+ mvwaddch (ctx -> window , /* y = */ graph_y , /* x = */ x + 2 , ' ' );
1067
1074
continue ;
1068
1075
}
1069
1076
@@ -1125,9 +1132,9 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
1125
1132
wattron (ctx -> window , COLOR_PAIR (color ));
1126
1133
1127
1134
if (has_utf8 ())
1128
- mvwprintw (ctx -> window , /* y = */ 3 , /* x = */ x + 2 , symbol );
1135
+ mvwprintw (ctx -> window , /* y = */ graph_y , /* x = */ x + graph_x , symbol );
1129
1136
else
1130
- mvwaddch (ctx -> window , /* y = */ 3 , /* x = */ x + 2 , symbolc );
1137
+ mvwaddch (ctx -> window , /* y = */ graph_y , /* x = */ x + graph_x , symbolc );
1131
1138
1132
1139
if (has_colors () == TRUE)
1133
1140
wattroff (ctx -> window , COLOR_PAIR (color ));
@@ -1140,7 +1147,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
1140
1147
return (0 );
1141
1148
} /* }}} int update_graph_prettyping */
1142
1149
1143
- static int update_graph_histogram (ping_context_t * ctx ) /* {{{ */
1150
+ static int update_graph_histogram (ping_context_t * ctx , int graph_x , int graph_y ) /* {{{ */
1144
1151
{
1145
1152
uint32_t * counters ;
1146
1153
uint32_t * accumulated ;
@@ -1220,12 +1227,12 @@ static int update_graph_histogram (ping_context_t *ctx) /* {{{ */
1220
1227
}
1221
1228
1222
1229
if (counters [x ] == 0 )
1223
- mvwaddch (ctx -> window , /* y = */ 3 , /* x = */ x + 2 , ' ' );
1230
+ mvwaddch (ctx -> window , /* y = */ graph_y , /* x = */ x + graph_x , ' ' );
1224
1231
else if (has_utf8 ())
1225
- mvwprintw (ctx -> window , /* y = */ 3 , /* x = */ x + 2 ,
1232
+ mvwprintw (ctx -> window , /* y = */ graph_y , /* x = */ x + graph_x ,
1226
1233
hist_symbols_utf8 [index ]);
1227
1234
else
1228
- mvwaddch (ctx -> window , /* y = */ 3 , /* x = */ x + 2 ,
1235
+ mvwaddch (ctx -> window , /* y = */ graph_y , /* x = */ x + graph_x ,
1229
1236
hist_symbols_acs [index ] | A_ALTCHARSET );
1230
1237
1231
1238
if (has_colors () == TRUE)
@@ -1250,13 +1257,18 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
1250
1257
1251
1258
/* werase (ctx->window); */
1252
1259
1253
- box (ctx -> window , 0 , 0 );
1260
+ if (opt_box ) {
1261
+ box (ctx -> window , 0 , 0 );
1262
+ }
1254
1263
wattron (ctx -> window , A_BOLD );
1255
- mvwprintw (ctx -> window , /* y = */ 0 , /* x = */ 5 ,
1264
+ mvwprintw (ctx -> window , /* y = */ 0 , /* x = */ opt_box ? 5 : 0 ,
1256
1265
" %s " , ctx -> host );
1257
1266
wattroff (ctx -> window , A_BOLD );
1258
- wprintw (ctx -> window , "ping statistics " );
1259
- mvwprintw (ctx -> window , /* y = */ 1 , /* x = */ 2 ,
1267
+ if (opt_box ) {
1268
+ wprintw (ctx -> window , "ping statistics " );
1269
+ wmove (ctx -> window , /* y = */ 1 , /* x = */ 2 );
1270
+ }
1271
+ wprintw (ctx -> window ,
1260
1272
"%i packets transmitted, %i received, %.2f%% packet "
1261
1273
"loss, time %.1fms" ,
1262
1274
ctx -> req_sent , ctx -> req_rcvd ,
@@ -1274,30 +1286,39 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
1274
1286
max = percentile_to_latency (ctx , 100.0 );
1275
1287
percentile = percentile_to_latency (ctx , opt_percentile );
1276
1288
1277
- mvwprintw (ctx -> window , /* y = */ 2 , /* x = */ 2 ,
1289
+ mvwprintw (ctx -> window , /* y = */ 1 + opt_box , /* x = */ opt_box * 2 ,
1278
1290
"RTT[ms]: min = %.0f, median = %.0f, p(%.0f) = %.0f, max = %.0f " ,
1279
1291
min , median , opt_percentile , percentile , max );
1280
1292
}
1281
1293
1282
- if (opt_show_graph == 1 )
1283
- update_graph_prettyping (ctx , latency );
1284
- else if (opt_show_graph == 2 )
1285
- update_graph_histogram (ctx );
1286
- else if (opt_show_graph == 3 )
1287
- update_graph_boxplot (ctx );
1294
+ if (opt_show_graph ) {
1295
+ int graph_x = opt_box * 2 ;
1296
+ int graph_y = 2 + opt_box ;
1297
+ if (opt_show_graph == 1 )
1298
+ update_graph_prettyping (ctx , graph_x , graph_y , latency );
1299
+ else if (opt_show_graph == 2 )
1300
+ update_graph_histogram (ctx , graph_x , graph_y );
1301
+ else if (opt_show_graph == 3 )
1302
+ update_graph_boxplot (ctx , graph_x , graph_y );
1303
+ }
1288
1304
1289
1305
wrefresh (ctx -> window );
1290
1306
1291
1307
return (0 );
1292
1308
} /* }}} int update_stats_from_context */
1293
1309
1310
+ static int get_box_height (void )
1311
+ {
1312
+ return (opt_show_graph == 0 ) ? 2 : 3 + opt_box * 2 ;
1313
+ }
1314
+
1294
1315
static int on_resize (pingobj_t * ping ) /* {{{ */
1295
1316
{
1296
1317
pingobj_iter_t * iter ;
1297
1318
int width = 0 ;
1298
1319
int height = 0 ;
1299
1320
int main_win_height ;
1300
- int box_height = ( opt_show_graph == 0 ) ? 4 : 5 ;
1321
+ int box_height = get_box_height () ;
1301
1322
1302
1323
getmaxyx (stdscr , height , width );
1303
1324
if ((height < 1 ) || (width < 1 ))
@@ -1394,7 +1415,7 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
1394
1415
int width = 0 ;
1395
1416
int height = 0 ;
1396
1417
int main_win_height ;
1397
- int box_height = ( opt_show_graph == 0 ) ? 4 : 5 ;
1418
+ int box_height = get_box_height () ;
1398
1419
1399
1420
initscr ();
1400
1421
cbreak ();
0 commit comments