Skip to content

Commit f0389dc

Browse files
committed
Use a simpler rounding up method for calculating the number of rows to reserve
1 parent 79fe321 commit f0389dc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/oping.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,8 @@ static int on_resize (pingobj_t *ping) /* {{{ */
12921292
if ((height < 1) || (width < 1))
12931293
return (EINVAL);
12941294

1295-
int box_rows_count = host_num / opt_columns;
1296-
if (box_rows_count < 1)
1297-
box_rows_count = 1;
1295+
/* calculate the number of box rows, rounding up */
1296+
int box_rows_count = (host_num+opt_columns-1) / opt_columns;
12981297

12991298
main_win_height = height - (box_height * box_rows_count);
13001299
wresize (main_win, main_win_height, /* width = */ width);
@@ -1385,9 +1384,8 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
13851384
init_pair (OPING_RED_HIST, COLOR_RED, COLOR_YELLOW);
13861385
}
13871386

1388-
int box_rows_count = host_num / opt_columns;
1389-
if (box_rows_count < 1)
1390-
box_rows_count = 1;
1387+
/* calculate the number of box rows, rounding up */
1388+
int box_rows_count = (host_num+opt_columns-1) / opt_columns;
13911389

13921390
main_win_height = height - (box_height * box_rows_count);
13931391
main_win = newwin (/* height = */ main_win_height,

0 commit comments

Comments
 (0)