7 Commits

Author SHA1 Message Date
Qwerasd
a1b682d0da fix(terminal): properly lookup hyperlinks when cloning rows across pages
Before this we were doing bad things with the memory, looking at
`PageEntry`s for links not actually in the page we were reading the
strings from.
2025-02-10 15:52:40 -05:00
Mitchell Hashimoto
6109edd00b terminal: refactor hyperlink memory management
Fixes #2500
Based on #2508

This separates out the concept of a "hyperlink" from a "hyperlink page
entry." The difference is that the former has real Zig slices into
things like strings and the latter has offsets into terminal page
memory.

From this separation, the Page structure now has an `insertHyperlink`
function that takes a hyperlink and converts it to a page entry.

This does a couple things: (1) it moves page memory management out of
Screen and into Page which is historically more appropriate and (2) it
let's us more easily test hyperlinks from the Page unit tests.

Finally, this PR makes some error sets explicit.
2024-10-28 15:30:04 -07:00
Mitchell Hashimoto
3b889438aa terminal: page clone handles case where hyperlink can't dupe
Fixes #1991

To check if a hyperlink from another page is already present in our
page's set, we need to dupe the hyperlink struct. If the hyperlink is
already present in our page, this dupe is a waste and is freed.

In the case where the hyperlink is present AND we don't have enough
memory to dupe the hyperlink to check if its present, we'd previous
simply crash out and fail rendering. Debug builds would crash with
integrity errors.

This commit resolves the issue by falling back to a slow path when our
string allocation table is full and iterating over the hyperlink map to
check one by one if we have the hyperlink. This O(N) is much slower than
allocating (in this case) but N is usually low on top of this case being
rare.

A better solution would probably be to ensure we always have some % of
available space free in our string allocation table. This would result
in some wasteful page reallocs but would speed up the render loop. We
can look into that later.
2024-07-22 17:01:25 -07:00
Mitchell Hashimoto
f777e42af2 terminal: page clone needs to clone strings 2024-07-05 21:40:39 -07:00
Mitchell Hashimoto
6fc9e92dba terminal: hyperlink deleted callback frees string memory 2024-07-05 21:40:37 -07:00
Mitchell Hashimoto
d1f41e2035 terminal: hyperlink start/end on screen 2024-07-05 21:39:55 -07:00
Mitchell Hashimoto
2a7755c515 terminal: hyperlink data structures beginning, alloc into page 2024-07-05 21:39:07 -07:00