aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/terminal/search/pagelist.zig
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:28:05 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:29:28 +0300
commit4a3302d19a2baa3a33e910e0088c24e780905b90 (patch)
treedcaf76fae1c82102d933c9225b17ca7ac5d3a847 /vendor/libghostty-vt/src/terminal/search/pagelist.zig
parent550e9f8cc085f428429f5cf2da0bb2dba897e8b8 (diff)
chore: update vendored libghostty-vt
refs #276
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/search/pagelist.zig')
-rw-r--r--vendor/libghostty-vt/src/terminal/search/pagelist.zig129
1 files changed, 119 insertions, 10 deletions
diff --git a/vendor/libghostty-vt/src/terminal/search/pagelist.zig b/vendor/libghostty-vt/src/terminal/search/pagelist.zig
index f76ad4e4..98a24c18 100644
--- a/vendor/libghostty-vt/src/terminal/search/pagelist.zig
+++ b/vendor/libghostty-vt/src/terminal/search/pagelist.zig
@@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
const testing = std.testing;
const terminal = @import("../main.zig");
const point = terminal.point;
+const size = terminal.size;
const FlattenedHighlight = @import("../highlight.zig").Flattened;
const Page = terminal.Page;
const PageList = terminal.PageList;
@@ -56,8 +57,8 @@ pub const PageListSearch = struct {
// be moved somewhere safe.
const pin = try list.trackPin(.{
.node = start,
- .y = start.data.size.rows - 1,
- .x = start.data.size.cols - 1,
+ .y = start.rows() - 1,
+ .x = start.cols() - 1,
});
errdefer list.untrackPin(pin);
@@ -84,6 +85,13 @@ pub const PageListSearch = struct {
self.list.untrackPin(self.pin);
}
+ /// Release owned search buffers after the PageList itself has already
+ /// been destroyed. Its pin belonged to the PageList pool and was freed
+ /// with that list, so it must not be untracked here.
+ pub fn deinitListInvalid(self: *PageListSearch) void {
+ self.window.deinit();
+ }
+
/// Return the next match in the loaded page nodes. If this returns
/// null then the PageList search needs to be fed the next node(s).
/// Call, `feed` to do this.
@@ -121,10 +129,13 @@ pub const PageListSearch = struct {
// get our desired amount of data.
var node_: ?*PageList.List.Node = self.pin.node.prev;
while (node_) |node| : (node_ = node.prev) {
- rem -|= try self.window.append(node);
+ rem -|= (try self.window.append(node)).content_len;
// Move our tracked pin to the new node.
self.pin.node = node;
+ self.pin.y = node.rows() - 1;
+ self.pin.x = node.cols() - 1;
+ self.pin.garbage = false;
if (rem == 0) break;
}
@@ -190,7 +201,7 @@ test "feed multiple pages with matches" {
defer s.deinit();
// Fill up first page
- const first_page_rows = t.screens.active.pages.pages.first.?.data.capacity.rows;
+ const first_page_rows = t.screens.active.pages.pages.first.?.capacity().rows;
for (0..first_page_rows - 1) |_| s.nextSlice("\r\n");
s.nextSlice("Fizz");
try testing.expect(t.screens.active.pages.pages.first == t.screens.active.pages.pages.last);
@@ -234,7 +245,7 @@ test "feed multiple pages no matches" {
defer s.deinit();
// Fill up first page
- const first_page_rows = t.screens.active.pages.pages.first.?.data.capacity.rows;
+ const first_page_rows = t.screens.active.pages.pages.first.?.capacity().rows;
for (0..first_page_rows - 1) |_| s.nextSlice("\r\n");
s.nextSlice("Hello");
@@ -272,7 +283,7 @@ test "feed iteratively through multiple matches" {
var s = t.vtStream();
defer s.deinit();
- const first_page_rows = t.screens.active.pages.pages.first.?.data.capacity.rows;
+ const first_page_rows = t.screens.active.pages.pages.first.?.capacity().rows;
// Fill first page with a match at the end
for (0..first_page_rows - 1) |_| s.nextSlice("\r\n");
@@ -313,7 +324,7 @@ test "feed with match spanning page boundary" {
var s = t.vtStream();
defer s.deinit();
- const first_page_rows = t.screens.active.pages.pages.first.?.data.capacity.rows;
+ const first_page_rows = t.screens.active.pages.pages.first.?.capacity().rows;
// Fill first page ending with "Te"
for (0..first_page_rows - 1) |_| s.nextSlice("\r\n");
@@ -359,6 +370,76 @@ test "feed with match spanning page boundary" {
try testing.expect(!try search.feed());
}
+test "compressed history match spanning page boundary remains compressed" {
+ const alloc = testing.allocator;
+ var t: Terminal = try .init(alloc, .{
+ .cols = 80,
+ .rows = 24,
+ .max_scrollback = 10 * 1024 * 1024,
+ });
+ defer t.deinit(alloc);
+
+ var stream = t.vtStream();
+ defer stream.deinit();
+
+ const pages = &t.screens.active.pages;
+ const first = pages.pages.first.?;
+ const first_page_rows = first.capacity().rows;
+
+ // Put half the needle on either side of a soft-wrapped page boundary.
+ for (0..first_page_rows - 1) |_| stream.nextSlice("\r\n");
+ for (0..pages.cols - 2) |_| stream.nextSlice("x");
+ stream.nextSlice("Test");
+ const second = first.next.?;
+ try testing.expectEqual(second, pages.pages.last.?);
+
+ // Move both matching pages completely into history. The third page holds
+ // the active area, making the first two eligible for compression.
+ while (pages.pages.last.? == second) stream.nextSlice("\r\n");
+ for (0..pages.rows) |_| stream.nextSlice("\r\n");
+ try testing.expect(pages.getTopLeft(.active).node != second);
+
+ _ = pages.compress(.full);
+ try testing.expectEqual(PageList.List.Node.Storage.compressed, first.storage());
+ try testing.expectEqual(PageList.List.Node.Storage.compressed, second.storage());
+ const compressed = pages.memoryStats();
+ try testing.expect(compressed.compressed_pages >= 2);
+
+ var search: PageListSearch = try .init(
+ alloc,
+ "Test",
+ pages,
+ pages.pages.last.?,
+ );
+ defer search.deinit();
+
+ // Drain and feed incrementally until the boundary match is available. The
+ // exact number of feeds depends on how much blank-page text the formatter
+ // trims, so bound progress by the number of pages rather than encoding
+ // that implementation detail in the test.
+ var found: ?FlattenedHighlight = null;
+ for (0..pages.totalPages() + 1) |_| {
+ if (search.next()) |match| {
+ found = match;
+ break;
+ }
+ if (!try search.feed()) break;
+ }
+ try testing.expect(found != null);
+
+ const match = found.?.untracked();
+ try testing.expectEqual(first, match.start.node);
+ try testing.expectEqual(second, match.end.node);
+ try testing.expectEqual(@as(size.CellCountInt, pages.cols - 2), match.start.x);
+ try testing.expectEqual(@as(size.CellCountInt, 1), match.end.x);
+
+ // Search owns formatted text and coordinate maps, not page snapshots. The
+ // original raw mappings therefore remain discarded after matching.
+ try testing.expectEqual(compressed, pages.memoryStats());
+ try testing.expectEqual(PageList.List.Node.Storage.compressed, first.storage());
+ try testing.expectEqual(PageList.List.Node.Storage.compressed, second.storage());
+}
+
test "feed with match spanning page boundary with newline" {
const alloc = testing.allocator;
var t: Terminal = try .init(alloc, .{ .cols = 80, .rows = 24 });
@@ -367,7 +448,7 @@ test "feed with match spanning page boundary with newline" {
var s = t.vtStream();
defer s.deinit();
- const first_page_rows = t.screens.active.pages.pages.first.?.data.capacity.rows;
+ const first_page_rows = t.screens.active.pages.pages.first.?.capacity().rows;
// Fill first page ending with "Te"
for (0..first_page_rows - 1) |_| s.nextSlice("\r\n");
@@ -404,14 +485,14 @@ test "feed with pruned page" {
// Grow to capacity
const page1_node = p.pages.last.?;
- const page1 = page1_node.data;
+ const page1 = page1_node.page();
for (0..page1.capacity.rows - page1.size.rows) |_| {
try testing.expect(try p.grow() == null);
}
// Grow and allocate one more page. Then fill that page up.
const page2_node = (try p.grow()).?;
- const page2 = page2_node.data;
+ const page2 = page2_node.page();
for (0..page2.capacity.rows - page2.size.rows) |_| {
try testing.expect(try p.grow() == null);
}
@@ -439,3 +520,31 @@ test "feed with pruned page" {
// Feed should still do nothing
try testing.expect(!try search.feed());
}
+
+test "feed keeps its tracked pin within a shorter page" {
+ const alloc = testing.allocator;
+ var pages: PageList = try .init(alloc, 10, 2, null);
+ defer pages.deinit();
+
+ const first = pages.pages.first.?;
+ while (first.rows() < first.capacity().rows) _ = try pages.grow();
+
+ const second = (try pages.grow()).?;
+ while (second.rows() < second.capacity().rows) _ = try pages.grow();
+
+ try pages.split(.{ .node = first, .y = 1, .x = 0 });
+ const shorter = first.next.?;
+ try testing.expect(shorter.rows() < second.rows());
+
+ var search: PageListSearch = try .init(
+ alloc,
+ "x",
+ &pages,
+ second,
+ );
+ defer search.deinit();
+
+ try testing.expect(try search.feed());
+ try testing.expectEqual(shorter, search.pin.node);
+ try testing.expect(pages.pinIsValid(search.pin.*));
+}