115 Commits

Author SHA1 Message Date
Mitchell Hashimoto
e712314f31 terminal: PageList.reset has to zero arena memory to avoid reuse
Fixes #2877

As the comment in the diff states, we rely on `mmap` to zero our memory.
When we reset we are reusing previously allocated memory so we won't hit
an `mmap`. We need to zero the memory ourselves.

This is pretty slow if there is a lot of memory but in every case except
allocation failures, we expect there to be only a few pages allocated.
2024-12-03 08:58:57 -05:00
Mitchell Hashimoto
d7fcaefdf3 terminal: PageList.reset 2024-12-02 17:26:19 -05:00
Mitchell Hashimoto
d57d1d2395 terminal: failing tracked pin test on fullReset 2024-12-02 09:39:43 -05:00
Mitchell Hashimoto
1335af3e4a terminal: change pagelist linked list to an intrusive linked list 2024-11-07 15:12:54 -08:00
Mitchell Hashimoto
aed51fd0b0 terminal: PageList rename "page" to "node" everywhere
This is more correct: a pagelist is a linked list of nodes, not pages.
The nodes themselves contain pages but we were previously calling the
nodes "pages" which was confusing, especially as I plan some future
changes to the way pages are stored.
2024-11-07 13:44:39 -08:00
Qwerasd
487f08b1dd fix(PageList, Page): fix off-by-1 in map capacity checks
We're already using `>=`, we don't need to also use `- 1`
2024-10-28 15:41:34 -07:00
Mitchell Hashimoto
f858ae13ae terminal: clarify comment 2024-09-21 21:05:46 -07:00
Mitchell Hashimoto
f0eb5d0d43 terminal: test for scenario where grow() has to prune with a single page
See comments in the test, also this:

> The scenario is if you adjustCapacity a page beyond a std_size then our
> precondition no longer holds. PageList.adjustCapacity makes no guarantee
> that the resulting capacity fits within a standard page size. It is in fact
> documented this way and that it is slow since we have to mmap out of our
> memory pool.
2024-09-21 21:05:01 -07:00
Khang Nguyen Duy
d5ab772b66 fix(terminal/PageList): ensure enough pages before first page reuse
Running alacritty/vtebench on some machines causes Ghostty to fail on
`assert(first != last)` when trying to grow scrollback. We now make sure
we have enough pages before trying to reuse pages.
2024-09-21 22:03:06 +07:00
Mitchell Hashimoto
5ade197f91 Merge pull request #2175 from qwerasd205/pagelist-fix
fix(terminal/PageList): update self.cols at start of resizeCols
2024-09-01 09:58:39 -07:00
Qwerasd
7fb2bd16a9 fix(terminal/PageList): update self.cols at start of resizeCols
It's possible for `self.grow` to be called within the body of the
function, and `self.grow` uses `self.cols` to create a new page if
there's no more room in the current one.
2024-09-01 09:55:00 -07:00
Mitchell Hashimoto
6aab430caf terminal: disable slow safety tests in releasesafe 2024-08-31 21:14:12 -07:00
Mitchell Hashimoto
9d08ed32ee terminal: make error sets more explicit, capture explicit errors 2024-08-31 10:31:38 -07:00
Qwerasd
5714c2feed PageList: refactor clone to avoid excess work
Also avoids leaving content in out-of-bounds rows, since it doesn't copy
the content to them in the first place. Over all, just a lot cleaner.
2024-08-27 01:23:29 -04:00
Qwerasd
d43d5b26ee fix(terminal): avoid trying to clone bad managed memory in reflow
If we call `moveLastRowToNewPage` at any point because we failed to copy
some managed memory, it tries to copy managed memory that hasn't been
cloned yet when moving our progress to a new page.

Avoid this by setting our content tag, hyperlink flag, and style id to
indicate no managed memory is present on the cell.
2024-08-27 01:01:31 -04:00
Mitchell Hashimoto
cff907940f renderer: do not extend padding color if any cell has default bg color
Before, cells that were explicitly set to match the default bg color
were treated as if they did NOT have the default and extending would
occur. We now check the exact RGB of each cell.
2024-08-22 14:57:46 -07:00
cryptocode
2e88ff1d05 Improve resize performance by switching to AutoArrayHashMapUnmanaged
I noticed that the HashMap iterator showed up prominently in Instruments when quickly
resizing Ghostty.

I think this is related to the [tombstone issue](https://github.com/ziglang/zig/issues/17851),
where the `next()` function has to skip unused meta-nodes.

In that same issue, Andrew is suggesting that the non-array hashmap might get deleted from the
standard library.

After switching to `AutoArrayHashMapUnmanaged`, iteration barely shows up anymore.

Deletion from the pin list should also be fast as swapRemove is used (order does not need to be preserved).

Question is if insertion performance is negatively affected, though I'm not seeing anything obvious.
Still, checking this PR for any perf regressions might be a good idea.

If this pans out, there are more places where this switch might be beneficial.
2024-08-10 23:54:04 +02:00
Mitchell Hashimoto
aeb3b64110 do not extend background for window-padding-color if powerline 2024-08-10 10:20:08 -07:00
Łukasz Niemier
f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02:00
Mitchell Hashimoto
ea551990eb renderer: disable window-padding-color=extend in certain scenarios
There are scenarios where this configuration looks bad. This commit
introduces some heuristics to prevent it. Here are the heuristics:

  * Extension is always enabled on alt screen.
  * Extension is disabled if a row contains any default bg color. The
    thinking is that in this scenario, using the default bg color looks
    just fine.
  * Extension is disabled if a row is marked as a prompt (using semantic
    prompt sequences). The thinking here is that prompts often contain
    perfect fit glyphs such as Powerline glyphs and those look bad when
    extended.

This introduces some CPU cost to the extension feature but it should be
minimal and respects dirty tracking. This is unfortunate but the feature
makes many terminal scenarios look much better and the performance cost
is minimal so I believe it is worth it.

Further heuristics are likely warranted but this should be a good
starting set.
2024-08-03 21:56:19 -07:00
Mitchell Hashimoto
2c4ddc594e terminal: reflow tests for kitty virtual placeholder flag 2024-07-31 09:48:00 -07:00
Mitchell Hashimoto
3549619a64 terminal: introduce row bit for kitty virtual placeholders 2024-07-25 21:32:45 -07:00
Mitchell Hashimoto
cf6463fec0 terminal/kitty: preparing to build runs of placements 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
13df93a1d0 temrinal/kitty: really basic row/col diacritic decoding 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
b103e31727 terminal: isBetween needs to fall through for matching y on top page
Regressed in 9198adcba3477ab521cf215f1f652813e32e1951

This was causing Kitty image intersection to break.
2024-07-25 21:32:28 -07:00
Mitchell Hashimoto
9198adcba3 terminal: Pin.isBetween broken logic
Two bugs:

1. If our pin is the top page, and self.y == top.y, then x will tell us
   the answer. Before, we'd fall through.

2. If our pin is not the top or bottom, but the top == bottom, then we
   can't possibly be between. Before, we'd incorrectly check the linked
   list starting AFTER top.
2024-07-20 14:50:31 -07:00
Qwerasd
8589f2c0fb terminal/PageList: rework reflow logic to fix issues
Reflow logic now lives inside of ReflowCursor. This fixes multiple
issues with the previous implementation, and is more straightforward
in how it works. The old impl resulted in fragmentation of pages,
leading to unbounded memory growth when resizing repeatedly.

Also improves the preserved_cursor logic in `resizeCols`.
2024-07-08 22:35:15 -04:00
Qwerasd
10dbca9464 terminal/PageList: fix some incorrect test expectations 2024-07-08 22:29:55 -04:00
Qwerasd
be99e50c50 terminal/PageList: add method for logging debug diagrams 2024-07-08 22:28:16 -04:00
Qwerasd
730185b212 terminal: spacer heads and tails should be codepoint 0, not ' ' 2024-07-08 22:25:39 -04:00
Mitchell Hashimoto
cdb838ea85 terminal: pause integrity checks on resize for hyperlink set 2024-07-05 21:40:40 -07:00
Mitchell Hashimoto
8b02d3430c terminal: copy hyperlinks on reflow 2024-07-05 21:40:39 -07:00
Mitchell Hashimoto
961a4b6b31 terminal: support page oom with hyperlinks 2024-07-05 21:40:39 -07:00
Mitchell Hashimoto
dea8859e2c Merge pull request #1925 from ghostty-org/styleref
terminal: when adjusting page capacity, account for cursor ref counts
2024-07-05 21:38:54 -07:00
Mitchell Hashimoto
92ffa9af13 terminal: when adjusting page capacity, account for cursor ref counts
This fixes an issue where when we adjusted the capacity of the page, the
style ref count would be off by one (short by one).

The issue is that when adjusting the capacity of a page, it happens on
PageList which is unware of cursor state and therefore can't ensure to
reference the active style.

This creates an `adjustCapacity` call on `Screen` which can properly
handle this scenario.
2024-07-05 21:33:05 -07:00
Mitchell Hashimoto
c02481530a terminal: Pin.isBetween incorrect if same y and same page 2024-07-05 19:06:57 -07:00
Mitchell Hashimoto
b62806360b terminal: add test for pagelist to clear styles 2024-06-24 20:58:11 -07:00
Qwerasd
6f732cca55 RefCountedSet: use usize for cap to allow up to max Id+1 2024-06-24 20:32:22 -07:00
Qwerasd
a7e6f1a070 fix(terminal/PageList): clear cells in truncated rows during clone
Previously this was a memory leak, styles and graphemes in these rows
were never reclaimed.
2024-06-24 20:32:21 -07:00
Qwerasd
9741b3a18c perf: introduce RefCountedSet structure, use it for Style.Set 2024-06-13 22:59:03 -04:00
Mitchell Hashimoto
cd42888182 terminal: eraseRows sets dirty bits 2024-05-07 10:38:27 -07:00
Mitchell Hashimoto
f975861891 terminal: maintain dirty bits when rotating rows on clone 2024-05-07 10:36:54 -07:00
Mitchell Hashimoto
3cfce658c3 terminal: dirty tracking in more places, tests coverage 2024-05-07 09:52:03 -07:00
Mitchell Hashimoto
7e52f94278 terminal: on clone, only mark rows dirty that were previously dirty 2024-05-01 20:31:49 -07:00
Mitchell Hashimoto
d47f14f86a terminal: dirty tracking on screen clone 2024-05-01 20:31:49 -07:00
Mitchell Hashimoto
f867fabf8e terminal: new coordinate type 2024-05-01 20:31:49 -07:00
Mitchell Hashimoto
19ddbbc7d6 terminal: eraseRowBounded dirty tracking 2024-05-01 20:31:48 -07:00
Mitchell Hashimoto
f7a57bd2c8 terminal: dirty tests on t/b/l/r margins 2024-05-01 20:31:48 -07:00
Mitchell Hashimoto
981f031951 terminal: remove unused debug log 2024-05-01 20:31:48 -07:00
Mitchell Hashimoto
11c195e493 terminal: dirty tracking on print with tests 2024-05-01 20:31:48 -07:00