aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-13 11:31:55 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:14:51 +0000
commitfd87bca102321e5804fef74dac8a6d267ae46732 (patch)
tree5473f7e53fd2b6cd9075d1b5d6b8b18a184a2ea4 /terminal.c
parenturl-mode: store URL in UTF-8, not UTF-32 (diff)
grid: enable rows to have ‘extra’ data associated with them
This patch adds an ‘extra’ member to the row struct. It is a pointer to a struct containing extra data to be associated with this row. Initially, this struct contains a list of URL ranges. These define (OSC-8) URLs on this row. The ‘extra’ data is allocated on-demand. I.e. the pointer is NULL by default; it is *not* allocated by grid_row_alloc().
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/terminal.c b/terminal.c
index 0051ca6d..17b985a8 100644
--- a/terminal.c
+++ b/terminal.c
@@ -2154,8 +2154,18 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
grid_swap_row(term->grid, i - rows, i);
/* Erase scrolled in lines */
- for (int r = region.end - rows; r < region.end; r++)
- erase_line(term, grid_row_and_alloc(term->grid, r));
+ for (int r = region.end - rows; r < region.end; r++) {
+ struct row *row = grid_row_and_alloc(term->grid, r);
+ if (unlikely(row->extra != NULL)) {
+ tll_foreach(row->extra->uri_ranges, it) {
+ free(it->item.uri);
+ tll_remove(row->extra->uri_ranges, it);
+ }
+ free(row->extra);
+ row->extra = NULL;
+ }
+ erase_line(term, row);
+ }
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row);
@@ -2222,8 +2232,18 @@ term_scroll_reverse_partial(struct terminal *term,
grid_swap_row(term->grid, i, i - rows);
/* Erase scrolled in lines */
- for (int r = region.start; r < region.start + rows; r++)
- erase_line(term, grid_row_and_alloc(term->grid, r));
+ for (int r = region.start; r < region.start + rows; r++) {
+ struct row *row = grid_row_and_alloc(term->grid, r);
+ if (unlikely(row->extra != NULL)) {
+ tll_foreach(row->extra->uri_ranges, it) {
+ free(it->item.uri);
+ tll_remove(row->extra->uri_ranges, it);
+ }
+ free(row->extra);
+ row->extra = NULL;
+ }
+ erase_line(term, row);
+ }
term_damage_scroll(term, DAMAGE_SCROLL_REVERSE, region, rows);
term->grid->cur_row = grid_row(term->grid, term->grid->cursor.point.row);