mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
terminal2/kitty: tests pass
This commit is contained in:
@ -1788,7 +1788,12 @@ pub const Pin = struct {
|
|||||||
|
|
||||||
if (self.page == top.page) {
|
if (self.page == top.page) {
|
||||||
if (self.y < top.y) return false;
|
if (self.y < top.y) return false;
|
||||||
if (self.y > top.y) return true;
|
if (self.y > top.y) {
|
||||||
|
return if (self.page == bottom.page)
|
||||||
|
self.y <= bottom.y
|
||||||
|
else
|
||||||
|
true;
|
||||||
|
}
|
||||||
return self.x >= top.x;
|
return self.x >= top.x;
|
||||||
}
|
}
|
||||||
if (self.page == bottom.page) {
|
if (self.page == bottom.page) {
|
||||||
|
@ -256,28 +256,44 @@ pub const ImageStorage = struct {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.intersect_cell => |v| {
|
.intersect_cell => |v| {
|
||||||
if (true) @panic("TODO");
|
self.deleteIntersecting(
|
||||||
const target = (point.Viewport{ .x = v.x, .y = v.y }).toScreen(&t.screen);
|
alloc,
|
||||||
self.deleteIntersecting(alloc, t, target, v.delete, {}, null);
|
t,
|
||||||
|
.{ .active = .{
|
||||||
|
.x = v.x,
|
||||||
|
.y = v.y,
|
||||||
|
} },
|
||||||
|
v.delete,
|
||||||
|
{},
|
||||||
|
null,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
.intersect_cell_z => |v| {
|
.intersect_cell_z => |v| {
|
||||||
if (true) @panic("TODO");
|
self.deleteIntersecting(
|
||||||
const target = (point.Viewport{ .x = v.x, .y = v.y }).toScreen(&t.screen);
|
alloc,
|
||||||
self.deleteIntersecting(alloc, t, target, v.delete, v.z, struct {
|
t,
|
||||||
fn filter(ctx: i32, p: Placement) bool {
|
.{ .active = .{
|
||||||
return p.z == ctx;
|
.x = v.x,
|
||||||
}
|
.y = v.y,
|
||||||
}.filter);
|
} },
|
||||||
|
v.delete,
|
||||||
|
v.z,
|
||||||
|
struct {
|
||||||
|
fn filter(ctx: i32, p: Placement) bool {
|
||||||
|
return p.z == ctx;
|
||||||
|
}
|
||||||
|
}.filter,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
.column => |v| {
|
.column => |v| {
|
||||||
if (true) @panic("TODO");
|
|
||||||
var it = self.placements.iterator();
|
var it = self.placements.iterator();
|
||||||
while (it.next()) |entry| {
|
while (it.next()) |entry| {
|
||||||
const img = self.imageById(entry.key_ptr.image_id) orelse continue;
|
const img = self.imageById(entry.key_ptr.image_id) orelse continue;
|
||||||
const rect = entry.value_ptr.rect(img, t);
|
const rect = entry.value_ptr.rect(img, t);
|
||||||
if (rect.top_left.x <= v.x and rect.bottom_right.x >= v.x) {
|
if (rect.top_left.x <= v.x and rect.bottom_right.x >= v.x) {
|
||||||
|
entry.value_ptr.deinit(t);
|
||||||
self.placements.removeByPtr(entry.key_ptr);
|
self.placements.removeByPtr(entry.key_ptr);
|
||||||
if (v.delete) self.deleteIfUnused(alloc, img.id);
|
if (v.delete) self.deleteIfUnused(alloc, img.id);
|
||||||
}
|
}
|
||||||
@ -287,16 +303,24 @@ pub const ImageStorage = struct {
|
|||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
.row => |v| {
|
.row => |v| row: {
|
||||||
if (true) @panic("TODO");
|
// v.y is in active coords so we want to convert it to a pin
|
||||||
// Get the screenpoint y
|
// so we can compare by page offsets.
|
||||||
const y = (point.Viewport{ .x = 0, .y = v.y }).toScreen(&t.screen).y;
|
const target_pin = t.screen.pages.pin(.{ .active = .{
|
||||||
|
.y = v.y,
|
||||||
|
} }) orelse break :row;
|
||||||
|
|
||||||
var it = self.placements.iterator();
|
var it = self.placements.iterator();
|
||||||
while (it.next()) |entry| {
|
while (it.next()) |entry| {
|
||||||
const img = self.imageById(entry.key_ptr.image_id) orelse continue;
|
const img = self.imageById(entry.key_ptr.image_id) orelse continue;
|
||||||
const rect = entry.value_ptr.rect(img, t);
|
const rect = entry.value_ptr.rect(img, t);
|
||||||
if (rect.top_left.y <= y and rect.bottom_right.y >= y) {
|
|
||||||
|
// We need to copy our pin to ensure we are at least at
|
||||||
|
// the top-left x.
|
||||||
|
var target_pin_copy = target_pin;
|
||||||
|
target_pin_copy.x = rect.top_left.x;
|
||||||
|
if (target_pin_copy.isBetween(rect.top_left, rect.bottom_right)) {
|
||||||
|
entry.value_ptr.deinit(t);
|
||||||
self.placements.removeByPtr(entry.key_ptr);
|
self.placements.removeByPtr(entry.key_ptr);
|
||||||
if (v.delete) self.deleteIfUnused(alloc, img.id);
|
if (v.delete) self.deleteIfUnused(alloc, img.id);
|
||||||
}
|
}
|
||||||
@ -307,11 +331,11 @@ pub const ImageStorage = struct {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.z => |v| {
|
.z => |v| {
|
||||||
if (true) @panic("TODO");
|
|
||||||
var it = self.placements.iterator();
|
var it = self.placements.iterator();
|
||||||
while (it.next()) |entry| {
|
while (it.next()) |entry| {
|
||||||
if (entry.value_ptr.z == v.z) {
|
if (entry.value_ptr.z == v.z) {
|
||||||
const image_id = entry.key_ptr.image_id;
|
const image_id = entry.key_ptr.image_id;
|
||||||
|
entry.value_ptr.deinit(t);
|
||||||
self.placements.removeByPtr(entry.key_ptr);
|
self.placements.removeByPtr(entry.key_ptr);
|
||||||
if (v.delete) self.deleteIfUnused(alloc, image_id);
|
if (v.delete) self.deleteIfUnused(alloc, image_id);
|
||||||
}
|
}
|
||||||
@ -814,120 +838,126 @@ test "storage: delete intersecting cursor" {
|
|||||||
}) != null);
|
}) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test "storage: delete intersecting cursor plus unused" {
|
test "storage: delete intersecting cursor plus unused" {
|
||||||
// const testing = std.testing;
|
const testing = std.testing;
|
||||||
// const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
// var t = try terminal.Terminal.init(alloc, 100, 100);
|
var t = try terminal.Terminal.init(alloc, 100, 100);
|
||||||
// defer t.deinit(alloc);
|
defer t.deinit(alloc);
|
||||||
// t.width_px = 100;
|
t.width_px = 100;
|
||||||
// t.height_px = 100;
|
t.height_px = 100;
|
||||||
//
|
const tracked = t.screen.pages.countTrackedPins();
|
||||||
// var s: ImageStorage = .{};
|
|
||||||
// defer s.deinit(alloc);
|
var s: ImageStorage = .{};
|
||||||
// try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
defer s.deinit(alloc, &t);
|
||||||
// try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
||||||
// try s.addPlacement(alloc, 1, 1, .{ .point = .{ .x = 0, .y = 0 } });
|
try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
||||||
// try s.addPlacement(alloc, 1, 2, .{ .point = .{ .x = 25, .y = 25 } });
|
try s.addPlacement(alloc, 1, 1, .{ .pin = try trackPin(&t, .{ .x = 0, .y = 0 }) });
|
||||||
//
|
try s.addPlacement(alloc, 1, 2, .{ .pin = try trackPin(&t, .{ .x = 25, .y = 25 }) });
|
||||||
// t.screen.cursor.x = 12;
|
|
||||||
// t.screen.cursor.y = 12;
|
t.screen.cursorAbsolute(12, 12);
|
||||||
//
|
|
||||||
// s.dirty = false;
|
s.dirty = false;
|
||||||
// s.delete(alloc, &t, .{ .intersect_cursor = true });
|
s.delete(alloc, &t, .{ .intersect_cursor = true });
|
||||||
// try testing.expect(s.dirty);
|
try testing.expect(s.dirty);
|
||||||
// try testing.expectEqual(@as(usize, 1), s.placements.count());
|
try testing.expectEqual(@as(usize, 1), s.placements.count());
|
||||||
// try testing.expectEqual(@as(usize, 2), s.images.count());
|
try testing.expectEqual(@as(usize, 2), s.images.count());
|
||||||
//
|
try testing.expectEqual(tracked + 1, t.screen.pages.countTrackedPins());
|
||||||
// // verify the placement is what we expect
|
|
||||||
// try testing.expect(s.placements.get(.{
|
// verify the placement is what we expect
|
||||||
// .image_id = 1,
|
try testing.expect(s.placements.get(.{
|
||||||
// .placement_id = .{ .tag = .external, .id = 2 },
|
.image_id = 1,
|
||||||
// }) != null);
|
.placement_id = .{ .tag = .external, .id = 2 },
|
||||||
// }
|
}) != null);
|
||||||
//
|
}
|
||||||
// test "storage: delete intersecting cursor hits multiple" {
|
|
||||||
// const testing = std.testing;
|
test "storage: delete intersecting cursor hits multiple" {
|
||||||
// const alloc = testing.allocator;
|
const testing = std.testing;
|
||||||
// var t = try terminal.Terminal.init(alloc, 100, 100);
|
const alloc = testing.allocator;
|
||||||
// defer t.deinit(alloc);
|
var t = try terminal.Terminal.init(alloc, 100, 100);
|
||||||
// t.width_px = 100;
|
defer t.deinit(alloc);
|
||||||
// t.height_px = 100;
|
t.width_px = 100;
|
||||||
//
|
t.height_px = 100;
|
||||||
// var s: ImageStorage = .{};
|
const tracked = t.screen.pages.countTrackedPins();
|
||||||
// defer s.deinit(alloc);
|
|
||||||
// try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
var s: ImageStorage = .{};
|
||||||
// try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
defer s.deinit(alloc, &t);
|
||||||
// try s.addPlacement(alloc, 1, 1, .{ .point = .{ .x = 0, .y = 0 } });
|
try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
||||||
// try s.addPlacement(alloc, 1, 2, .{ .point = .{ .x = 25, .y = 25 } });
|
try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
||||||
//
|
try s.addPlacement(alloc, 1, 1, .{ .pin = try trackPin(&t, .{ .x = 0, .y = 0 }) });
|
||||||
// t.screen.cursor.x = 26;
|
try s.addPlacement(alloc, 1, 2, .{ .pin = try trackPin(&t, .{ .x = 25, .y = 25 }) });
|
||||||
// t.screen.cursor.y = 26;
|
|
||||||
//
|
t.screen.cursorAbsolute(26, 26);
|
||||||
// s.dirty = false;
|
|
||||||
// s.delete(alloc, &t, .{ .intersect_cursor = true });
|
s.dirty = false;
|
||||||
// try testing.expect(s.dirty);
|
s.delete(alloc, &t, .{ .intersect_cursor = true });
|
||||||
// try testing.expectEqual(@as(usize, 0), s.placements.count());
|
try testing.expect(s.dirty);
|
||||||
// try testing.expectEqual(@as(usize, 1), s.images.count());
|
try testing.expectEqual(@as(usize, 0), s.placements.count());
|
||||||
// }
|
try testing.expectEqual(@as(usize, 1), s.images.count());
|
||||||
//
|
try testing.expectEqual(tracked, t.screen.pages.countTrackedPins());
|
||||||
// test "storage: delete by column" {
|
}
|
||||||
// const testing = std.testing;
|
|
||||||
// const alloc = testing.allocator;
|
test "storage: delete by column" {
|
||||||
// var t = try terminal.Terminal.init(alloc, 100, 100);
|
const testing = std.testing;
|
||||||
// defer t.deinit(alloc);
|
const alloc = testing.allocator;
|
||||||
// t.width_px = 100;
|
var t = try terminal.Terminal.init(alloc, 100, 100);
|
||||||
// t.height_px = 100;
|
defer t.deinit(alloc);
|
||||||
//
|
t.width_px = 100;
|
||||||
// var s: ImageStorage = .{};
|
t.height_px = 100;
|
||||||
// defer s.deinit(alloc);
|
const tracked = t.screen.pages.countTrackedPins();
|
||||||
// try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
|
||||||
// try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
var s: ImageStorage = .{};
|
||||||
// try s.addPlacement(alloc, 1, 1, .{ .point = .{ .x = 0, .y = 0 } });
|
defer s.deinit(alloc, &t);
|
||||||
// try s.addPlacement(alloc, 1, 2, .{ .point = .{ .x = 25, .y = 25 } });
|
try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
||||||
//
|
try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
||||||
// s.dirty = false;
|
try s.addPlacement(alloc, 1, 1, .{ .pin = try trackPin(&t, .{ .x = 0, .y = 0 }) });
|
||||||
// s.delete(alloc, &t, .{ .column = .{
|
try s.addPlacement(alloc, 1, 2, .{ .pin = try trackPin(&t, .{ .x = 25, .y = 25 }) });
|
||||||
// .delete = false,
|
|
||||||
// .x = 60,
|
s.dirty = false;
|
||||||
// } });
|
s.delete(alloc, &t, .{ .column = .{
|
||||||
// try testing.expect(s.dirty);
|
.delete = false,
|
||||||
// try testing.expectEqual(@as(usize, 1), s.placements.count());
|
.x = 60,
|
||||||
// try testing.expectEqual(@as(usize, 2), s.images.count());
|
} });
|
||||||
//
|
try testing.expect(s.dirty);
|
||||||
// // verify the placement is what we expect
|
try testing.expectEqual(@as(usize, 1), s.placements.count());
|
||||||
// try testing.expect(s.placements.get(.{
|
try testing.expectEqual(@as(usize, 2), s.images.count());
|
||||||
// .image_id = 1,
|
try testing.expectEqual(tracked + 1, t.screen.pages.countTrackedPins());
|
||||||
// .placement_id = .{ .tag = .external, .id = 1 },
|
|
||||||
// }) != null);
|
// verify the placement is what we expect
|
||||||
// }
|
try testing.expect(s.placements.get(.{
|
||||||
//
|
.image_id = 1,
|
||||||
// test "storage: delete by row" {
|
.placement_id = .{ .tag = .external, .id = 1 },
|
||||||
// const testing = std.testing;
|
}) != null);
|
||||||
// const alloc = testing.allocator;
|
}
|
||||||
// var t = try terminal.Terminal.init(alloc, 100, 100);
|
|
||||||
// defer t.deinit(alloc);
|
test "storage: delete by row" {
|
||||||
// t.width_px = 100;
|
const testing = std.testing;
|
||||||
// t.height_px = 100;
|
const alloc = testing.allocator;
|
||||||
//
|
var t = try terminal.Terminal.init(alloc, 100, 100);
|
||||||
// var s: ImageStorage = .{};
|
defer t.deinit(alloc);
|
||||||
// defer s.deinit(alloc);
|
t.width_px = 100;
|
||||||
// try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
t.height_px = 100;
|
||||||
// try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
const tracked = t.screen.pages.countTrackedPins();
|
||||||
// try s.addPlacement(alloc, 1, 1, .{ .point = .{ .x = 0, .y = 0 } });
|
|
||||||
// try s.addPlacement(alloc, 1, 2, .{ .point = .{ .x = 25, .y = 25 } });
|
var s: ImageStorage = .{};
|
||||||
//
|
defer s.deinit(alloc, &t);
|
||||||
// s.dirty = false;
|
try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
|
||||||
// s.delete(alloc, &t, .{ .row = .{
|
try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
|
||||||
// .delete = false,
|
try s.addPlacement(alloc, 1, 1, .{ .pin = try trackPin(&t, .{ .x = 0, .y = 0 }) });
|
||||||
// .y = 60,
|
try s.addPlacement(alloc, 1, 2, .{ .pin = try trackPin(&t, .{ .x = 25, .y = 25 }) });
|
||||||
// } });
|
|
||||||
// try testing.expect(s.dirty);
|
s.dirty = false;
|
||||||
// try testing.expectEqual(@as(usize, 1), s.placements.count());
|
s.delete(alloc, &t, .{ .row = .{
|
||||||
// try testing.expectEqual(@as(usize, 2), s.images.count());
|
.delete = false,
|
||||||
//
|
.y = 60,
|
||||||
// // verify the placement is what we expect
|
} });
|
||||||
// try testing.expect(s.placements.get(.{
|
try testing.expect(s.dirty);
|
||||||
// .image_id = 1,
|
try testing.expectEqual(@as(usize, 1), s.placements.count());
|
||||||
// .placement_id = .{ .tag = .external, .id = 1 },
|
try testing.expectEqual(@as(usize, 2), s.images.count());
|
||||||
// }) != null);
|
try testing.expectEqual(tracked + 1, t.screen.pages.countTrackedPins());
|
||||||
// }
|
|
||||||
|
// verify the placement is what we expect
|
||||||
|
try testing.expect(s.placements.get(.{
|
||||||
|
.image_id = 1,
|
||||||
|
.placement_id = .{ .tag = .external, .id = 1 },
|
||||||
|
}) != null);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user