grid: reflow: use macro print_spacer() to insert multi-column character spacers

This commit is contained in:
Daniel Eklöf 2020-07-14 20:29:59 +02:00
parent f962fb236e
commit b0798ad0be
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

19
grid.c
View file

@ -183,6 +183,13 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
} \
} while(0)
#define print_spacer() \
do { \
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER; \
new_row->cells[new_col_idx].attrs = old_cell->attrs; \
new_row->cells[new_col_idx].attrs.clean = 1; \
} while (0)
/*
* Keep track of empty cells. If the old line ends with a
* string of empty cells, we don't need to, nor do we want to,
@ -231,11 +238,8 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
/* Out of columns on current row in new grid? */
if (new_col_idx + max(1, wcwidth(old_cell->wc)) > new_cols) {
/* Pad to end-of-line with spacers, then line-wrap */
for (;new_col_idx < new_cols; new_col_idx++) {
new_row->cells[new_col_idx] = (struct cell){};
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER;
new_row->cells[new_col_idx].attrs.clean = 1;
}
for (;new_col_idx < new_cols; new_col_idx++)
print_spacer();
line_wrap();
}
@ -262,9 +266,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
* subsequent cells */
for (size_t i = 0; i < width - 1; i++) {
assert(new_col_idx < new_cols);
new_row->cells[new_col_idx] = (struct cell){};
new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER;
new_row->cells[new_col_idx].attrs.clean = 1;
print_spacer();
new_col_idx++;
}
}
@ -278,6 +280,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
line_wrap();
}
#undef print_spacer
#undef line_wrap
}