From 1a0de0017f7b2061bad0b695a98963ca0f274e21 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 13:42:07 +0100 Subject: grid: add grid_row_uri_range_erase() This function handles erasing of an URI range. That is, a range of the row is being either erased, or overwritten (from the URI perspective, these two are the same thing). We handle both partial overwrites (split up, or truncate URI), as well as complete overwrites (remove URI). --- terminal.c | 74 ++------------------------------------------------------------ 1 file changed, 2 insertions(+), 72 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index bf13dd46..3100e3a4 100644 --- a/terminal.c +++ b/terminal.c @@ -1781,63 +1781,7 @@ erase_cell_range(struct terminal *term, struct row *row, int start, int end) } else memset(&row->cells[start], 0, (end - start + 1) * sizeof(row->cells[0])); - if (likely(row->extra == NULL)) - return; - - /* Split up, or remove, URI ranges affected by the erase */ - tll_foreach(row->extra->uri_ranges, it) { - if (it->item.start > end) { - /* This range, and all subsequent ranges, start *after* - * the erase range */ - break; - } - - if (it->item.start < start && it->item.end >= start) { - /* - * URI crosses the erase *start* point. - * - * Create a new range for the URI part *before* the erased - * cells. - * - * Also modify this URI range’s start point so that we can - * remove it below. - */ - struct row_uri_range range_before = { - .start = it->item.start, - .end = start - 1, - .id = it->item.id, - .uri = xstrdup(it->item.uri), - }; - tll_insert_before(row->extra->uri_ranges, it, range_before); - it->item.start = start; - } - - if (it->item.start <= end && it->item.end > end) { - /* - * URI crosses the erase *end* point. - * - * Create a new range for the URI part *after* the erased - * cells. - * - * Also modify the URI range’s end point so that we can - * remove it below. - */ - struct row_uri_range range_after = { - .start = end + 1, - .end = it->item.end, - .id = it->item.id, - .uri = xstrdup(it->item.uri), - }; - tll_insert_before(row->extra->uri_ranges, it, range_after); - it->item.end = end; - } - - if (it->item.start >= start && it->item.end <= end) { - /* URI range completey covered by the erase - remove it */ - free(it->item.uri); - tll_remove(row->extra->uri_ranges, it); - } - } + grid_row_uri_range_erase(row, start, end); } static inline void @@ -3590,21 +3534,7 @@ term_osc8_close(struct terminal *term) .id = term->vt.osc8.id, .uri = xstrdup(term->vt.osc8.uri), }; - grid_row_add_uri_range(row, range); - -#if defined(_DEBUG) - tll_foreach(row->extra->uri_ranges, it1) { - tll_foreach(row->extra->uri_ranges, it2) { - if (&it1->item == &it2->item) - continue; - - xassert(it1->item.start != it2->item.start); - xassert(it1->item.start != it2->item.end); - xassert(it1->item.end != it2->item.start); - xassert(it1->item.end != it2->item.end); - } - } -#endif + grid_row_uri_range_add(row, range); start_col = 0; if (r == end.row) -- cgit v1.3 From 09a331857a8480ebce4aec83e665a0c68e6a03c4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 13:54:30 +0100 Subject: term: call grid_row_uri_range_erase() when printing cells --- terminal.c | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 3100e3a4..7bf912e8 100644 --- a/terminal.c +++ b/terminal.c @@ -3162,6 +3162,8 @@ term_print(struct terminal *term, wchar_t wc, int width) { xassert(width > 0); + struct grid *grid = term->grid; + if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && wc >= 0x60 && wc <= 0x7e) { @@ -3180,24 +3182,26 @@ term_print(struct terminal *term, wchar_t wc, int width) print_linewrap(term); print_insert(term, width); + int col = grid->cursor.point.col; + if (unlikely(width > 1) && likely(term->auto_margin) && - term->grid->cursor.point.col + width > term->cols) + col + width > term->cols) { /* 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++) + for (size_t i = col; i < term->cols; i++) print_spacer(term, i, 0); /* And force a line-wrap */ - term->grid->cursor.lcf = 1; + grid->cursor.lcf = 1; print_linewrap(term); } sixel_overwrite_at_cursor(term, width); /* *Must* get current cell *after* linewrap+insert */ - struct row *row = term->grid->cur_row; - struct cell *cell = &row->cells[term->grid->cursor.point.col]; + struct row *row = grid->cur_row; + struct cell *cell = &row->cells[col]; cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; @@ -3205,18 +3209,22 @@ term_print(struct terminal *term, wchar_t wc, int width) row->dirty = true; row->linebreak = true; + grid_row_uri_range_erase(row, col, col + width - 1); + /* 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++; - print_spacer(term, term->grid->cursor.point.col, width - i); + for (int i = 1; i < width && col < term->cols - 1; i++) { + col++; + print_spacer(term, col, width - i); } /* Advance cursor */ - if (unlikely(++term->grid->cursor.point.col >= term->cols)) { - term->grid->cursor.lcf = true; - term->grid->cursor.point.col--; + if (unlikely(++col >= term->cols)) { + grid->cursor.lcf = true; + col--; } else - xassert(!term->grid->cursor.lcf); + xassert(!grid->cursor.lcf); + + grid->cursor.point.col = col; } static void @@ -3228,15 +3236,18 @@ ascii_printer_generic(struct terminal *term, wchar_t wc) static void ascii_printer_fast(struct terminal *term, wchar_t wc) { + struct grid *grid = term->grid; + xassert(term->charsets.set[term->charsets.selected] == CHARSET_ASCII); xassert(!term->insert_mode); - xassert(tll_length(term->grid->sixel_images) == 0); + xassert(tll_length(grid->sixel_images) == 0); print_linewrap(term); /* *Must* get current cell *after* linewrap+insert */ - struct row *row = term->grid->cur_row; - struct cell *cell = &row->cells[term->grid->cursor.point.col]; + int col = grid->cursor.point.col; + struct row *row = grid->cur_row; + struct cell *cell = &row->cells[col]; cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; @@ -3244,12 +3255,16 @@ ascii_printer_fast(struct terminal *term, wchar_t wc) row->dirty = true; row->linebreak = true; + grid_row_uri_range_erase(row, col, col); + /* Advance cursor */ - if (unlikely(++term->grid->cursor.point.col >= term->cols)) { - term->grid->cursor.lcf = true; - term->grid->cursor.point.col--; + if (unlikely(++col >= term->cols)) { + grid->cursor.lcf = true; + col--; } else - xassert(!term->grid->cursor.lcf); + xassert(!grid->cursor.lcf); + + grid->cursor.point.col = col; } static void -- cgit v1.3 From 53fc1a1cb12fc2367a1ff76e723be52603c39cdc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 14:39:32 +0100 Subject: term: tail-call optimize calls to grid_row_uri_range_erase() --- terminal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 7bf912e8..120f7ac3 100644 --- a/terminal.c +++ b/terminal.c @@ -3209,7 +3209,7 @@ term_print(struct terminal *term, wchar_t wc, int width) row->dirty = true; row->linebreak = true; - grid_row_uri_range_erase(row, col, col + width - 1); + int uri_start = col; /* Advance cursor the 'additional' columns while dirty:ing the cells */ for (int i = 1; i < width && col < term->cols - 1; i++) { @@ -3225,6 +3225,9 @@ term_print(struct terminal *term, wchar_t wc, int width) xassert(!grid->cursor.lcf); grid->cursor.point.col = col; + + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, uri_start, uri_start + width - 1); } static void @@ -3255,7 +3258,7 @@ ascii_printer_fast(struct terminal *term, wchar_t wc) row->dirty = true; row->linebreak = true; - grid_row_uri_range_erase(row, col, col); + int uri_start = col; /* Advance cursor */ if (unlikely(++col >= term->cols)) { @@ -3265,6 +3268,9 @@ ascii_printer_fast(struct terminal *term, wchar_t wc) xassert(!grid->cursor.lcf); grid->cursor.point.col = col; + + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, uri_start, uri_start); } static void -- cgit v1.3 From 0be55ef74c38140877d82c66159f112517b3825c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 20 Nov 2021 14:40:03 +0100 Subject: term: erase_cell_range(): check if row->extra != NULL --- terminal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 120f7ac3..ea7da6e3 100644 --- a/terminal.c +++ b/terminal.c @@ -1781,7 +1781,8 @@ erase_cell_range(struct terminal *term, struct row *row, int start, int end) } else memset(&row->cells[start], 0, (end - start + 1) * sizeof(row->cells[0])); - grid_row_uri_range_erase(row, start, end); + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, start, end); } static inline void -- cgit v1.3 From 3c6239c66f0ea758655a891492073fd3549cd877 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 14:13:27 +0100 Subject: term: print: re-order col/row/cell assigments --- terminal.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index ea7da6e3..1da97335 100644 --- a/terminal.c +++ b/terminal.c @@ -3202,15 +3202,14 @@ term_print(struct terminal *term, wchar_t wc, int width) /* *Must* get current cell *after* linewrap+insert */ struct row *row = grid->cur_row; - struct cell *cell = &row->cells[col]; + row->dirty = true; + row->linebreak = true; + struct cell *cell = &row->cells[col]; cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; - row->dirty = true; - row->linebreak = true; - - int uri_start = col; + const int uri_start = col; /* Advance cursor the 'additional' columns while dirty:ing the cells */ for (int i = 1; i < width && col < term->cols - 1; i++) { @@ -3250,16 +3249,16 @@ ascii_printer_fast(struct terminal *term, wchar_t wc) /* *Must* get current cell *after* linewrap+insert */ int col = grid->cursor.point.col; + const int uri_start = col; + struct row *row = grid->cur_row; - struct cell *cell = &row->cells[col]; + row->dirty = true; + row->linebreak = true; + struct cell *cell = &row->cells[col]; cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; - row->dirty = true; - row->linebreak = true; - - int uri_start = col; /* Advance cursor */ if (unlikely(++col >= term->cols)) { -- cgit v1.3 From 65944906bf87bf7ea6c404526fa3f3f88f96194a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 14:14:08 +0100 Subject: term: print: erase URI range when printing right-margin padding --- terminal.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 1da97335..21733cf5 100644 --- a/terminal.c +++ b/terminal.c @@ -3193,6 +3193,9 @@ term_print(struct terminal *term, wchar_t wc, int width) for (size_t i = col; i < term->cols; i++) print_spacer(term, i, 0); + if (grid->cur_row->extra != NULL) + grid_row_uri_range_erase(grid->cur_row, col, term->cols - 1); + /* And force a line-wrap */ grid->cursor.lcf = 1; print_linewrap(term); -- cgit v1.3 From 315769b50bd3df2d41cb130200bc03eb64be4078 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 14:46:05 +0100 Subject: Revert "term: print: erase URI range when printing right-margin padding" This reverts commit bb967fd2f927d90e881ed2b05db1fa6946033580. --- terminal.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 21733cf5..1da97335 100644 --- a/terminal.c +++ b/terminal.c @@ -3193,9 +3193,6 @@ term_print(struct terminal *term, wchar_t wc, int width) for (size_t i = col; i < term->cols; i++) print_spacer(term, i, 0); - if (grid->cur_row->extra != NULL) - grid_row_uri_range_erase(grid->cur_row, col, term->cols - 1); - /* And force a line-wrap */ grid->cursor.lcf = 1; print_linewrap(term); -- cgit v1.3 From 5b176dd5d6e55dd666b0e424cae20e7a97e3bede Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Nov 2021 14:47:24 +0100 Subject: term: print: reset ‘col’ after padding the right margin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 1da97335..4cc9ed09 100644 --- a/terminal.c +++ b/terminal.c @@ -3196,6 +3196,7 @@ term_print(struct terminal *term, wchar_t wc, int width) /* And force a line-wrap */ grid->cursor.lcf = 1; print_linewrap(term); + col = 0; } sixel_overwrite_at_cursor(term, width); -- cgit v1.3