Skip to content

Commit 7997ae2

Browse files
committed
noping: boxless drawing option
1 parent 74470ba commit 7997ae2

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
@@ -183,6 +183,10 @@ and routing.
183183
I<noping only> B<-u> forces UTF-8 output, B<-U> disables UTF-8 output. If
184184
neither is given, the codeset is automatically determined from the locale.
185185

186+
=item B<-B>
187+
188+
I<noping only> B<-B> disables drawing boxes around the ping results.
189+
186190
=item B<-g> B<none>|B<prettyping>|B<boxplot>|B<histogram>
187191

188192
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
@@ -207,6 +207,7 @@ static double opt_exit_status_threshold = 1.0;
207207
#if USE_NCURSES
208208
static int opt_show_graph = 1;
209209
static int opt_utf8 = 0;
210+
static int opt_box = 1;
210211
#endif
211212

212213
static int host_num = 0;
@@ -443,6 +444,7 @@ static void usage_exit (const char *name, int status) /* {{{ */
443444
#if USE_NCURSES
444445
" -u / -U force / disable UTF-8 output\n"
445446
" -g graph graph type to draw\n"
447+
" -B don't draw boxes\n"
446448
#endif
447449
" -P percent Report the n'th percentile of latency\n"
448450
" -Z percent Exit with non-zero exit status if more than this percentage of\n"
@@ -649,7 +651,7 @@ static int read_options (int argc, char **argv) /* {{{ */
649651

650652
while (1)
651653
{
652-
optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:m:w:"
654+
optchar = getopt (argc, argv, "46Bc:hi:I:t:Q:f:D:Z:P:m:w:"
653655
#if USE_NCURSES
654656
"uUg:"
655657
#endif
@@ -780,6 +782,10 @@ static int read_options (int argc, char **argv) /* {{{ */
780782
case 'U':
781783
opt_utf8 = 1;
782784
break;
785+
786+
case 'B':
787+
opt_box = 0;
788+
break;
783789
#endif
784790

785791
case 'Z':
@@ -880,7 +886,7 @@ static _Bool has_utf8() /* {{{ */
880886
# endif
881887
} /* }}} _Bool has_utf8 */
882888

883-
static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
889+
static int update_graph_boxplot (ping_context_t *ctx, int graph_x, int graph_y) /* {{{ */
884890
{
885891
uint32_t *counters;
886892
double *ratios;
@@ -973,8 +979,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
973979

974980
if (reverse)
975981
wattron (ctx->window, A_REVERSE);
976-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ (int) (x + 2), symbol);
977-
// mvwprintw (ctx->window, /* y = */ 3, /* x = */ (int) (x + 2), symbol);
982+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ (int) (x + graph_x), symbol);
983+
// mvwprintw (ctx->window, /* y = */ graph_y, /* x = */ (int) (x + graph_x), symbol);
978984
if (reverse)
979985
wattroff (ctx->window, A_REVERSE);
980986
}
@@ -984,7 +990,8 @@ static int update_graph_boxplot (ping_context_t *ctx) /* {{{ */
984990
return (0);
985991
} /* }}} int update_graph_boxplot */
986992

987-
static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
993+
static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
994+
int graph_x, int graph_y,
988995
double latency, unsigned int sequence)
989996
{
990997
size_t x;
@@ -1025,7 +1032,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
10251032

10261033
if (x >= ctx->history_size)
10271034
{
1028-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, ' ');
1035+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + 2, ' ');
10291036
continue;
10301037
}
10311038

@@ -1083,9 +1090,9 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
10831090
wattron (ctx->window, COLOR_PAIR(color));
10841091

10851092
if (has_utf8())
1086-
mvwprintw (ctx->window, /* y = */ 3, /* x = */ x + 2, symbol);
1093+
mvwprintw (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x, symbol);
10871094
else
1088-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, symbolc);
1095+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x, symbolc);
10891096

10901097
if (has_colors () == TRUE)
10911098
wattroff (ctx->window, COLOR_PAIR(color));
@@ -1098,7 +1105,7 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
10981105
return (0);
10991106
} /* }}} int update_graph_prettyping */
11001107

1101-
static int update_graph_histogram (ping_context_t *ctx) /* {{{ */
1108+
static int update_graph_histogram (ping_context_t *ctx, int graph_x, int graph_y) /* {{{ */
11021109
{
11031110
uint32_t *counters;
11041111
uint32_t *accumulated;
@@ -1178,12 +1185,12 @@ static int update_graph_histogram (ping_context_t *ctx) /* {{{ */
11781185
}
11791186

11801187
if (counters[x] == 0)
1181-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2, ' ');
1188+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x, ' ');
11821189
else if (has_utf8 ())
1183-
mvwprintw (ctx->window, /* y = */ 3, /* x = */ x + 2,
1190+
mvwprintw (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x,
11841191
hist_symbols_utf8[index]);
11851192
else
1186-
mvwaddch (ctx->window, /* y = */ 3, /* x = */ x + 2,
1193+
mvwaddch (ctx->window, /* y = */ graph_y, /* x = */ x + graph_x,
11871194
hist_symbols_acs[index] | A_ALTCHARSET);
11881195

11891196
if (has_colors () == TRUE)
@@ -1214,13 +1221,18 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
12141221

12151222
/* werase (ctx->window); */
12161223

1217-
box (ctx->window, 0, 0);
1224+
if (opt_box) {
1225+
box (ctx->window, 0, 0);
1226+
}
12181227
wattron (ctx->window, A_BOLD);
1219-
mvwprintw (ctx->window, /* y = */ 0, /* x = */ 5,
1228+
mvwprintw (ctx->window, /* y = */ 0, /* x = */ opt_box ? 5 : 0,
12201229
" %s ", ctx->host);
12211230
wattroff (ctx->window, A_BOLD);
1222-
wprintw (ctx->window, "ping statistics ");
1223-
mvwprintw (ctx->window, /* y = */ 1, /* x = */ 2,
1231+
if (opt_box) {
1232+
wprintw (ctx->window, "ping statistics ");
1233+
wmove (ctx->window, /* y = */ 1, /* x = */ 2);
1234+
}
1235+
wprintw (ctx->window,
12241236
"%i packets transmitted, %i received, %.2f%% packet "
12251237
"loss, time %.1fms",
12261238
ctx->req_sent, ctx->req_rcvd,
@@ -1238,30 +1250,39 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
12381250
max = percentile_to_latency (ctx, 100.0);
12391251
percentile = percentile_to_latency (ctx, opt_percentile);
12401252

1241-
mvwprintw (ctx->window, /* y = */ 2, /* x = */ 2,
1253+
mvwprintw (ctx->window, /* y = */ 1 + opt_box, /* x = */ opt_box * 2,
12421254
"RTT[ms]: min = %.0f, median = %.0f, p(%.0f) = %.0f, max = %.0f ",
12431255
min, median, opt_percentile, percentile, max);
12441256
}
12451257

1246-
if (opt_show_graph == 1)
1247-
update_graph_prettyping (ctx, latency, sequence);
1248-
else if (opt_show_graph == 2)
1249-
update_graph_histogram (ctx);
1250-
else if (opt_show_graph == 3)
1251-
update_graph_boxplot (ctx);
1258+
if (opt_show_graph) {
1259+
int graph_x = opt_box * 2;
1260+
int graph_y = 2 + opt_box;
1261+
if (opt_show_graph == 1)
1262+
update_graph_prettyping (ctx, graph_x, graph_y, latency, sequence);
1263+
else if (opt_show_graph == 2)
1264+
update_graph_histogram (ctx, graph_x, graph_y);
1265+
else if (opt_show_graph == 3)
1266+
update_graph_boxplot (ctx, graph_x, graph_y);
1267+
}
12521268

12531269
wrefresh (ctx->window);
12541270

12551271
return (0);
12561272
} /* }}} int update_stats_from_context */
12571273

1274+
static int get_box_height (void)
1275+
{
1276+
return (opt_show_graph == 0) ? 2 : 3 + opt_box * 2;
1277+
}
1278+
12581279
static int on_resize (pingobj_t *ping) /* {{{ */
12591280
{
12601281
pingobj_iter_t *iter;
12611282
int width = 0;
12621283
int height = 0;
12631284
int main_win_height;
1264-
int box_height = (opt_show_graph == 0) ? 4 : 5;
1285+
int box_height = get_box_height();
12651286

12661287
getmaxyx (stdscr, height, width);
12671288
if ((height < 1) || (width < 1))
@@ -1332,7 +1353,7 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
13321353
int width = 0;
13331354
int height = 0;
13341355
int main_win_height;
1335-
int box_height = (opt_show_graph == 0) ? 4 : 5;
1356+
int box_height = get_box_height();
13361357

13371358
initscr ();
13381359
cbreak ();

0 commit comments

Comments
 (0)