diff --git a/grid.c b/grid.c index 3a595b61..4ccb27ac 100644 --- a/grid.c +++ b/grid.c @@ -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 }