From df2927e088ceb2119264d1a970c22a450f00005b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 14 Jul 2020 16:49:11 +0200 Subject: term: print: write special value CELL_MULT_COL_SPACER to extra cells When printing a multi-column character, write CELL_MULT_COL_SPACER instead of '0' to both padding cells (when character doesn't fit at the end of the line), and to the cells following the actual character. --- terminal.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index eda311da..2a232de3 100644 --- a/terminal.c +++ b/terminal.c @@ -2397,18 +2397,15 @@ term_print(struct terminal *term, wchar_t wc, int width) term->grid->cursor.point.col + width > term->cols) { /* Multi-column character that doesn't fit on current line - - * force a line wrap */ - term->grid->cursor.lcf = 1; + * pad with spacers */ + for (size_t i = term->grid->cursor.point.col; i < term->cols; i++) { + struct cell *cell = &term->grid->cur_row->cells[i]; + cell->wc = CELL_MULT_COL_SPACER; + cell->attrs.clean = 0; + } - /* - * TODO: should we insert place holder values in the remaining - * cells? This would allow e.g. text extraction to simply - * skip these, instead of trying to recognize a sequence of - * empty cells at the end of the line followed by a - * multi-column character... - * - * Might also make text reflow easier, or even more correct. - */ + /* And force a line-wrap */ + term->grid->cursor.lcf = 1; } print_linewrap(term); @@ -2431,7 +2428,7 @@ term_print(struct terminal *term, wchar_t wc, int width) term->grid->cursor.point.col++; struct cell *cell = &row->cells[term->grid->cursor.point.col]; - cell->wc = 0; + cell->wc = CELL_MULT_COL_SPACER; cell->attrs.clean = 0; } -- cgit v1.3 From 6d7aba3ea07b9a7a584dcb027fa8f0f26c5c4fd5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 14 Jul 2020 17:03:20 +0200 Subject: term: print: linewrap + insert *before* inserting SPACERS Otherwise we end up overwriting the character in the last column --- terminal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 2a232de3..e9bb0812 100644 --- a/terminal.c +++ b/terminal.c @@ -2393,6 +2393,9 @@ term_print(struct terminal *term, wchar_t wc, int width) if (unlikely(width <= 0)) return; + print_linewrap(term); + print_insert(term, width); + if (unlikely(width > 1) && term->grid->cursor.point.col + width > term->cols) { @@ -2406,11 +2409,9 @@ term_print(struct terminal *term, wchar_t wc, int width) /* And force a line-wrap */ term->grid->cursor.lcf = 1; + print_linewrap(term); } - print_linewrap(term); - print_insert(term, width); - sixel_overwrite_at_cursor(term, width); /* *Must* get current cell *after* linewrap+insert */ -- cgit v1.3 From f962fb236ecfb76e01589865022817d9bf9133b7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 14 Jul 2020 20:24:52 +0200 Subject: term: copy current VT attributes to multi-column spacer cells And refactor: break out spacer-writing code to a function, since we do exactly the same thing in two places. --- terminal.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index e9bb0812..78c72ada 100644 --- a/terminal.c +++ b/terminal.c @@ -2387,6 +2387,17 @@ print_insert(struct terminal *term, int width) row->cells[i].attrs.clean = 0; } +static void +print_spacer(struct terminal *term, int col) +{ + struct row *row = term->grid->cur_row; + struct cell *cell = &row->cells[col]; + + cell->wc = CELL_MULT_COL_SPACER; + cell->attrs = term->vt.attrs; + cell->attrs.clean = 0; +} + void term_print(struct terminal *term, wchar_t wc, int width) { @@ -2401,11 +2412,8 @@ term_print(struct terminal *term, wchar_t wc, int width) { /* Multi-column character that doesn't fit on current line - * pad with spacers */ - for (size_t i = term->grid->cursor.point.col; i < term->cols; i++) { - struct cell *cell = &term->grid->cur_row->cells[i]; - cell->wc = CELL_MULT_COL_SPACER; - cell->attrs.clean = 0; - } + for (size_t i = term->grid->cursor.point.col; i < term->cols; i++) + print_spacer(term, i); /* And force a line-wrap */ term->grid->cursor.lcf = 1; @@ -2427,10 +2435,7 @@ term_print(struct terminal *term, wchar_t wc, int width) /* Advance cursor the 'additional' columns while dirty:ing the cells */ for (int i = 1; i < width && term->grid->cursor.point.col < term->cols - 1; i++) { term->grid->cursor.point.col++; - - struct cell *cell = &row->cells[term->grid->cursor.point.col]; - cell->wc = CELL_MULT_COL_SPACER; - cell->attrs.clean = 0; + print_spacer(term, term->grid->cursor.point.col); } /* Advance cursor */ -- cgit v1.3 From 2fa2c9fad4c401b174e084ee560defba7c6ca49e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 15 Jul 2020 08:04:51 +0200 Subject: term: print: don't pad with spacers if auto-margin is disabled --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 78c72ada..40bfbc90 100644 --- a/terminal.c +++ b/terminal.c @@ -2407,7 +2407,7 @@ term_print(struct terminal *term, wchar_t wc, int width) print_linewrap(term); print_insert(term, width); - if (unlikely(width > 1) && + if (unlikely(width > 1) && likely(term->auto_margin) && term->grid->cursor.point.col + width > term->cols) { /* Multi-column character that doesn't fit on current line - -- cgit v1.3