From b0798ad0bed7dac45c167040644df6599cc390f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 14 Jul 2020 20:29:59 +0200 Subject: [PATCH] grid: reflow: use macro print_spacer() to insert multi-column character spacers --- grid.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 }