mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-07 04:06:07 -05:00
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().
This commit is contained in:
parent
3339915d20
commit
fd87bca102
3 changed files with 44 additions and 4 deletions
9
grid.c
9
grid.c
|
|
@ -33,6 +33,7 @@ grid_row_alloc(int cols, bool initialize)
|
|||
struct row *row = xmalloc(sizeof(*row));
|
||||
row->dirty = false;
|
||||
row->linebreak = false;
|
||||
row->extra = NULL;
|
||||
|
||||
if (initialize) {
|
||||
row->cells = xcalloc(cols, sizeof(row->cells[0]));
|
||||
|
|
@ -50,6 +51,14 @@ grid_row_free(struct row *row)
|
|||
if (row == NULL)
|
||||
return;
|
||||
|
||||
if (row->extra != NULL) {
|
||||
tll_foreach(row->extra->uri_ranges, it) {
|
||||
free(it->item.uri);
|
||||
tll_remove(row->extra->uri_ranges, it);
|
||||
}
|
||||
}
|
||||
|
||||
free(row->extra);
|
||||
free(row->cells);
|
||||
free(row);
|
||||
}
|
||||
|
|
|
|||
28
terminal.c
28
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);
|
||||
|
|
|
|||
11
terminal.h
11
terminal.h
|
|
@ -86,10 +86,21 @@ struct composed {
|
|||
uint8_t count;
|
||||
};
|
||||
|
||||
struct row_uri_range {
|
||||
int start;
|
||||
int end;
|
||||
char *uri;
|
||||
};
|
||||
|
||||
struct row_data {
|
||||
tll(struct row_uri_range) uri_ranges;
|
||||
};
|
||||
|
||||
struct row {
|
||||
struct cell *cells;
|
||||
bool dirty;
|
||||
bool linebreak;
|
||||
struct row_data *extra;
|
||||
};
|
||||
|
||||
struct sixel {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue