aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-15 06:20:10 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-15 06:20:10 +0000
commit6b0b3ddcccf27fd08b77945d71409ac26dfe94dc (patch)
tree837f8ae2002a0d1f91871731d370bfda77b9ba51 /grid.c
parentselection: recognize empty padding cells in a forced linewrap (diff)
parentterm: print: don't pad with spacers if auto-margin is disabled (diff)
Merge branch 'multi-column-special-spacer-value'
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/grid.c b/grid.c
index d2905a93..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,
@@ -222,12 +229,19 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
/* Multi-column characters are never cut in half */
assert(c + width <= old_cols);
- for (int i = 0; i < empty_count + width; i++) {
+ for (int i = 0; i < empty_count + 1; i++) {
const struct cell *old_cell = &old_row->cells[c - empty_count + i];
+ if (old_cell->wc == CELL_MULT_COL_SPACER)
+ continue;
+
/* Out of columns on current row in new grid? */
- if (new_col_idx + max(1, wcwidth(old_cell->wc)) > new_cols)
+ 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++)
+ print_spacer();
line_wrap();
+ }
assert(new_row != NULL);
assert(new_col_idx >= 0);
@@ -247,6 +261,14 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
}
}
new_col_idx++;
+
+ /* For multi-column characters, insert spacers in the
+ * subsequent cells */
+ for (size_t i = 0; i < width - 1; i++) {
+ assert(new_col_idx < new_cols);
+ print_spacer();
+ new_col_idx++;
+ }
}
c += width - 1;
@@ -258,6 +280,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
line_wrap();
}
+#undef print_spacer
#undef line_wrap
}