diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-11-22 20:50:30 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-11-22 20:50:30 +0000 |
| commit | 4a47730f15971765e169c07160f23ec056d77c91 (patch) | |
| tree | 0b70bb7c45785b50dff10fa8f67301d0202461ff /terminal.c | |
| parent | changelog: pipe-* key bindings not being parsed correctly (diff) | |
| parent | term: print: reset ‘col’ after padding the right margin (diff) | |
Merge branch 'osc8-overwrite-2'
Closes #801
Closes #804
Diffstat (limited to 'terminal.c')
| -rw-r--r-- | terminal.c | 142 |
1 files changed, 47 insertions, 95 deletions
@@ -1781,63 +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])); - 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); - } - } + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, start, end); } static inline void @@ -3218,6 +3163,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) { @@ -3236,43 +3183,52 @@ 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); + col = 0; } 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; + 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; + const int uri_start = col; /* 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; + + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, uri_start, uri_start + width - 1); } static void @@ -3284,28 +3240,38 @@ 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; + const int uri_start = col; + + struct row *row = grid->cur_row; + 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; /* 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; + + if (unlikely(row->extra != NULL)) + grid_row_uri_range_erase(row, uri_start, uri_start); } static void @@ -3590,21 +3556,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) |
