Skip to content

Commit d0f8e12

Browse files
committed
noping: boxless drawing option
1 parent eea8d6d commit d0f8e12

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

src/mans/oping.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ and routing.
189189
I<noping only> B<-u> forces UTF-8 output, B<-U> disables UTF-8 output. If
190190
neither is given, the codeset is automatically determined from the locale.
191191

192+
=item B<-B>
193+
194+
I<noping only> B<-B> disables drawing boxes around the ping results.
195+
192196
=item B<-g> B<none>|B<prettyping>|B<boxplot>|B<histogram>
193197

194198
I<noping only> Selects the graph to display.

src/oping.c

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static double opt_exit_status_threshold = 1.0;
213213
#if USE_NCURSES
214214
static int opt_show_graph = 1;
215215
static int opt_utf8 = 0;
216+
static int opt_box = 1;
216217
#endif
217218
static char *opt_outfile = NULL;
218219
static int opt_bell = 0;
@@ -471,6 +472,7 @@ static void usage_exit (const char *name, int status) /* {{{ */
471472
#if USE_NCURSES
472473
" -u / -U force / disable UTF-8 output\n"
473474
" -g graph graph type to draw\n"
475+
" -B don't draw boxes\n"
474476
#endif
475477
" -P percent Report the n'th percentile of latency\n"
476478
" -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) /* {{{ */
677679

678680
while (1)
679681
{
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"
681683
#if USE_NCURSES
682684
"uUg:"
683685
#endif
@@ -815,6 +817,10 @@ static int read_options (int argc, char **argv) /* {{{ */
815817
case 'U':
816818
opt_utf8 = 1;
817819
break;
820+
821+
case 'B':
822+
opt_box = 0;
823+
break;
818824
#endif
819825
case 'b':
820826
opt_bell = 1;
@@ -918,7 +924,7 @@ static _Bool has_utf8() /* {{{ */
918924
# endif
919925
} /* }}} _Bool has_utf8 */
920926

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) /* {{{ */
922928
{
923929
uint32_t *counters;
924930
double *ratios;
@@ -1011,8 +1017,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
10111017

10121018
if (reverse)
10131019
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);
10161022
if (reverse)
10171023
wattroff (ctx->window, A_REVERSE);
10181024
}
@@ -1022,7 +1028,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
10221028
return (0);
10231029
} /* }}} int update_graph_boxplot */
10241030

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,
10261033
double latency)
10271034
{
10281035
size_t x;
@@ -1063,7 +1070,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
10631070

10641071
if (x >= ctx->history_size)
10651072
{
1066-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, ' ');
1073+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + 2, ' ');
10671074
continue;
10681075
}
10691076

@@ -1125,9 +1132,9 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
11251132
wattron (ctx->window, COLOR_PAIR(color));
11261133

11271134
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);
11291136
else
1130-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, symbolc);
1137+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x, symbolc);
11311138

11321139
if (has_colors () == TRUE)
11331140
wattroff (ctx->window, COLOR_PAIR(color));
@@ -1140,7 +1147,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
11401147
return (0);
11411148
} /* }}} int update_graph_prettyping */
11421149

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) /* {{{ */
11441151
{
11451152
uint32_t *counters;
11461153
uint32_t *accumulated;
@@ -1220,12 +1227,12 @@ static int update_graph_histogram (ping_context_t *ctx) /* {{{ */
12201227
}
12211228

12221229
if (counters[x] == 0)
1223-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, ' ');
1230+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x, ' ');
12241231
else if (has_utf8 ())
1225-
mvwprintw (ctx->window, /* y = */ 3, /* x = */ x + 2,
1232+
mvwprintw (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x,
12261233
hist_symbols_utf8[index]);
12271234
else
1228-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2,
1235+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x,
12291236
hist_symbols_acs[index] | A_ALTCHARSET);
12301237

12311238
if (has_colors () == TRUE)
@@ -1250,13 +1257,18 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
12501257

12511258
/* werase (ctx->window); */
12521259

1253-
box (ctx->window, 0, 0);
1260+
if (opt_box) {
1261+
box (ctx->window, 0, 0);
1262+
}
12541263
wattron (ctx->window, A_BOLD);
1255-
mvwprintw (ctx->window, /* y = */ 0, /* x = */ 5,
1264+
mvwprintw (ctx->window, /* y = */ 0, /* x = */ opt_box ? 5 : 0,
12561265
" %s ", ctx->host);
12571266
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,
12601272
"%i packets transmitted, %i received, %.2f%% packet "
12611273
"loss, time %.1fms",
12621274
ctx->req_sent, ctx->req_rcvd,
@@ -1274,30 +1286,39 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
12741286
max = percentile_to_latency (ctx, 100.0);
12751287
percentile = percentile_to_latency (ctx, opt_percentile);
12761288

1277-
mvwprintw (ctx->window, /* y = */ 2, /* x = */ 2,
1289+
mvwprintw (ctx->window, /* y = */ 1 + opt_box, /* x = */ opt_box * 2,
12781290
"RTT[ms]: min = %.0f, median = %.0f, p(%.0f) = %.0f, max = %.0f ",
12791291
min, median, opt_percentile, percentile, max);
12801292
}
12811293

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+
}
12881304

12891305
wrefresh (ctx->window);
12901306

12911307
return (0);
12921308
} /* }}} int update_stats_from_context */
12931309

1310+
static int get_box_height (void)
1311+
{
1312+
return (opt_show_graph == 0) ? 2 : 3 + opt_box * 2;
1313+
}
1314+
12941315
static int on_resize (pingobj_t *ping) /* {{{ */
12951316
{
12961317
pingobj_iter_t *iter;
12971318
int width = 0;
12981319
int height = 0;
12991320
int main_win_height;
1300-
int box_height = (opt_show_graph == 0) ? 4 : 5;
1321+
int box_height = get_box_height();
13011322

13021323
getmaxyx (stdscr, height, width);
13031324
if ((height < 1) || (width < 1))
@@ -1394,7 +1415,7 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
13941415
int width = 0;
13951416
int height = 0;
13961417
int main_win_height;
1397-
int box_height = (opt_show_graph == 0) ? 4 : 5;
1418+
int box_height = get_box_height();
13981419

13991420
initscr ();
14001421
cbreak ();

0 commit comments

Comments
 (0)