From d9e1aefb9173857f0632227de5ac368a505c69bf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 14 May 2021 14:41:02 +0200 Subject: term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definition Instead of using CELL_SPACER for *all* cells that previously used CELL_MULT_COL_SPACER, include the remaining number of spacers following, and including, itself. This is encoded by adding to the CELL_SPACER value. So, a double width character will now store the character itself in the first cell (just like before), and CELL_SPACER+1 in the second cell. A three-cell character would store the character itself, then CELL_SPACER+2, and finally CELL_SPACER+1. In other words, the last spacer is always CELL_SPACER+1. CELL_SPACER+0 is used when padding at the right margin. I.e. when writing e.g. a double width character in the last column, we insert a CELL_SPACER+0 pad character, and then write the double width character in the first column on the next row. --- grid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'grid.c') diff --git a/grid.c b/grid.c index 8f0bb99f..ab8135f0 100644 --- a/grid.c +++ b/grid.c @@ -473,9 +473,9 @@ grid_resize_and_reflow( grid, new_grid, new_row, &new_row_idx, &new_col_idx, \ new_rows, new_cols) -#define print_spacer() \ +#define print_spacer(remaining) \ do { \ - new_row->cells[new_col_idx].wc = CELL_MULT_COL_SPACER; \ + new_row->cells[new_col_idx].wc = CELL_SPACER + (remaining); \ new_row->cells[new_col_idx].attrs = old_cell->attrs; \ new_row->cells[new_col_idx].attrs.clean = 1; \ } while (0) @@ -541,7 +541,7 @@ grid_resize_and_reflow( const struct cell *old_cell = &old_row->cells[c - empty_count + i]; wc = old_cell->wc; - if (wc == CELL_MULT_COL_SPACER) + if (wc >= CELL_SPACER) continue; if (wc >= CELL_COMB_CHARS_LO && @@ -554,7 +554,7 @@ grid_resize_and_reflow( if (new_col_idx + max(1, wcwidth(wc)) > new_cols) { /* Pad to end-of-line with spacers, then line-wrap */ for (;new_col_idx < new_cols; new_col_idx++) - print_spacer(); + print_spacer(0); line_wrap(); } @@ -585,7 +585,7 @@ grid_resize_and_reflow( const struct cell *old_cell = &old_row->cells[c]; for (size_t i = 0; i < width - 1; i++) { xassert(new_col_idx < new_cols); - print_spacer(); + print_spacer(width - i + 1); new_col_idx++; } -- cgit v1.3