Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a multiple columns layout feature #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/mans/oping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ configuration:

=back

=item B<-C> I<columns>

Sets the number of columns to display in the I<noping> graph layout. Note
that if the window is not wide enough to display all the information then
some of the graph data will display in a corrupted fashion.

=item B<-P> I<percent>

Configures the latency percentile to report. I<percent> must be a number
Expand Down
25 changes: 20 additions & 5 deletions src/oping.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ static double opt_exit_status_threshold = 1.0;
static int opt_show_graph = 1;
static int opt_box_height = MAX_BOX_HEIGHT;
static int opt_utf8 = 0;
static int opt_columns = 1;
#endif
static char *opt_outfile = NULL;
static int opt_bell = 0;
Expand Down Expand Up @@ -684,7 +685,7 @@ static int read_options (int argc, char **argv) /* {{{ */
{
optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:O:P:m:w:b"
#if USE_NCURSES
"uUg:H:"
"uUg:H:C:"
#endif
);

Expand Down Expand Up @@ -832,6 +833,16 @@ static int read_options (int argc, char **argv) /* {{{ */
case 'U':
opt_utf8 = 1;
break;
case 'C':
{
int new_columns = atoi(optarg);
if (new_columns > 0)
opt_columns = new_columns;
else
fprintf (stderr, "Ignoring invalid number of columns: %s\n",
optarg);
break;
}
#endif
case 'b':
opt_bell = 1;
Expand Down Expand Up @@ -1357,7 +1368,10 @@ static int create_windows (pingobj_t *ping) /* {{{ */
if ((height < 1) || (width < 1))
return (EINVAL);

main_win_height = height - (box_height * host_num);
/* calculate the number of box rows, rounding up */
int box_rows_count = (host_num+opt_columns-1) / opt_columns;

main_win_height = height - (box_height * box_rows_count);
if (main_win != NULL )
{
delwin(main_win);
Expand All @@ -1367,7 +1381,6 @@ static int create_windows (pingobj_t *ping) /* {{{ */
/* width = */ width,
/* y = */ 0, /* x = */ 0);


/* Allow scrolling */
scrollok (main_win, TRUE);
/* wsetscrreg (main_win, 0, main_win_height - 1); */
Expand All @@ -1376,6 +1389,8 @@ static int create_windows (pingobj_t *ping) /* {{{ */
wmove (main_win, /* y = */ main_win_height - 1, /* x = */ 0);
wrefresh (main_win);

width = width / opt_columns;

for (iter = ping_iterator_get (ping);
iter != NULL;
iter = ping_iterator_next (iter))
Expand All @@ -1395,8 +1410,8 @@ static int create_windows (pingobj_t *ping) /* {{{ */
}
context->window = newwin (/* height = */ box_height,
/* width = */ width,
/* y = */ main_win_height + (box_height * context->index),
/* x = */ 0);
/* y = */ main_win_height + (box_height * (context->index / opt_columns)),
/* x = */ width * (context->index % opt_columns));
}

return (0);
Expand Down