aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/terminal/SelectionGesture.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/terminal/SelectionGesture.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/terminal/SelectionGesture.zig')
-rw-r--r--vendor/libghostty-vt/src/terminal/SelectionGesture.zig193
1 files changed, 87 insertions, 106 deletions
diff --git a/vendor/libghostty-vt/src/terminal/SelectionGesture.zig b/vendor/libghostty-vt/src/terminal/SelectionGesture.zig
index 2be1e8aa..a842b247 100644
--- a/vendor/libghostty-vt/src/terminal/SelectionGesture.zig
+++ b/vendor/libghostty-vt/src/terminal/SelectionGesture.zig
@@ -83,13 +83,6 @@ const point = @import("point.zig");
const freestanding_wasm = builtin.target.cpu.arch == .wasm32 and
builtin.target.os.tag == .freestanding;
-/// Monotonic timestamp type for click-repeat detection.
-///
-/// Freestanding wasm cannot reference std.time.Instant because Zig's stdlib
-/// Instant type depends on POSIX timespec for that target, so represent the C
-/// API nanosecond timestamp directly as a u64 there.
-pub const Time = if (freestanding_wasm) u64 else std.time.Instant;
-
/// The tracked pin of the initial left click along with the screen
/// that the pin is part of.
left_click_pin: ?*Pin,
@@ -100,7 +93,7 @@ left_click_screen_generation: usize,
/// The left click time was the last time the left click was done, if the
/// caller could provide one. If this is null then we only support single clicks.
left_click_count: u3,
-left_click_time: ?Time,
+left_click_time: ?std.Io.Timestamp,
/// The selection behavior chosen for the active left-click gesture.
left_click_behavior: Behavior,
@@ -232,7 +225,7 @@ pub const Press = struct {
/// backwards timestamps reset the repeat sequence.
/// This can be null if you're on a system that doesn't support
/// time for some reason. In that case, we only support single clicks.
- time: ?Time,
+ time: ?std.Io.Timestamp,
/// The cell where the click was.
///
@@ -666,14 +659,11 @@ fn pressRepeat(
self.left_click_behavior = p.behaviors[self.left_click_count - 1];
}
-fn timeSince(time: Time, prev_time: Time) ?u64 {
- if (comptime freestanding_wasm) {
- if (time < prev_time) return null;
- return time - prev_time;
- }
+fn timeSince(time: std.Io.Timestamp, prev_time: std.Io.Timestamp) ?u64 {
+ const delta = prev_time.durationTo(time).toNanoseconds();
+ if (delta < 0) return null;
- if (time.order(prev_time) == .lt) return null;
- return time.since(prev_time);
+ return @as(u64, @intCast(@min(delta, std.math.maxInt(u64))));
}
/// Convert a caller-provided floating-point position to a pixel coordinate.
@@ -947,7 +937,7 @@ fn untrackPin(self: *SelectionGesture, t: *Terminal) void {
screen.pages.untrackPin(pin);
}
-fn testPress(t: *Terminal, x: u16, y: u32, time: ?std.time.Instant) Press {
+fn testPress(t: *Terminal, x: u16, y: u32, time: ?std.Io.Timestamp) Press {
return .{
.time = time,
.pin = t.screens.active.pages.pin(.{ .active = .{
@@ -962,16 +952,6 @@ fn testPress(t: *Terminal, x: u16, y: u32, time: ?std.time.Instant) Press {
};
}
-fn testInstant(ns: u64) std.time.Instant {
- return switch (builtin.os.tag) {
- .windows, .uefi, .wasi => .{ .timestamp = ns },
- else => .{ .timestamp = .{
- .sec = @intCast(ns / std.time.ns_per_s),
- .nsec = @intCast(ns % std.time.ns_per_s),
- } },
- };
-}
-
fn testDrag(t: *Terminal, x: u16, y: u32, xpos: f64, ypos: f64) Drag {
return .{
.pin = t.screens.active.pages.pin(.{ .active = .{
@@ -1049,7 +1029,7 @@ fn testDragSelection(
.padding_left = 5,
.screen_height = 110,
};
- var screen = try Screen.init(testing.allocator, .{ .cols = 10, .rows = 5, .max_scrollback = 0 });
+ var screen = try Screen.init(testing.io, testing.allocator, .{ .cols = 10, .rows = 5, .max_scrollback_bytes = 0 });
defer screen.deinit();
const click_pin = screen.pages.pin(.{
@@ -1110,7 +1090,7 @@ fn testDragSelectionIsNull(
.padding_left = 5,
.screen_height = 110,
};
- var screen = try Screen.init(testing.allocator, .{ .cols = 10, .rows = 5, .max_scrollback = 0 });
+ var screen = try Screen.init(testing.io, testing.allocator, .{ .cols = 10, .rows = 5, .max_scrollback_bytes = 0 });
defer screen.deinit();
const click_pin = screen.pages.pin(.{
@@ -1430,13 +1410,13 @@ test "SelectionGesture rectangle drag selection logic" {
}
test "SelectionGesture press records initial click" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 2, time));
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
@@ -1447,14 +1427,14 @@ test "SelectionGesture press records initial click" {
}
test "SelectionGesture press returns standard click selections" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta\none two");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
var event = testPress(&t, 1, 0, time);
event.word_boundary_codepoints = &.{ ' ' };
@@ -1474,14 +1454,14 @@ test "SelectionGesture press returns standard click selections" {
}
test "SelectionGesture press behaviors choose press and drag behavior" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta\none two\nthree four");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
var event = testPress(&t, 1, 0, time);
event.behaviors = &.{ .cell, .line, .word };
event.word_boundary_codepoints = &.{ ' ' };
@@ -1506,7 +1486,7 @@ test "SelectionGesture press behaviors choose press and drag behavior" {
}
test "SelectionGesture output behavior selects and drags semantic output" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 10, .rows = 6 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 10, .rows = 6 });
defer t.deinit(testing.allocator);
const screen = t.screens.active;
@@ -1522,7 +1502,7 @@ test "SelectionGesture output behavior selects and drags semantic output" {
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var event = testPress(&t, 1, 0, try std.time.Instant.now());
+ var event = testPress(&t, 1, 0, std.Io.Timestamp.now(testing.io, .awake));
event.behaviors = &.{ .output, .word, .line };
const press_selection = (try gesture.press(&t, event)).?;
@@ -1542,13 +1522,13 @@ test "SelectionGesture output behavior selects and drags semantic output" {
}
test "SelectionGesture drag returns selection and records autoscroll" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
@@ -1570,13 +1550,13 @@ test "SelectionGesture drag returns selection and records autoscroll" {
}
test "SelectionGesture drag clamps unrepresentable positions" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
@@ -1594,13 +1574,13 @@ test "SelectionGesture drag clamps unrepresentable positions" {
}
test "SelectionGesture drag saturates overflowing geometry" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
var drag_event = testDrag(&t, 1, 1, 10, 50);
drag_event.geometry.columns = std.math.maxInt(u32);
drag_event.geometry.cell_width = std.math.maxInt(u32);
@@ -1608,13 +1588,13 @@ test "SelectionGesture drag saturates overflowing geometry" {
}
test "SelectionGesture drag rejects empty geometry" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
var drag_event = testDrag(&t, 1, 1, 10, 50);
drag_event.geometry.columns = 0;
drag_event.geometry.cell_width = 0;
@@ -1622,13 +1602,13 @@ test "SelectionGesture drag rejects empty geometry" {
}
test "SelectionGesture release clears autoscroll and records drag" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
try testing.expectEqual(false, gesture.left_click_dragged);
_ = gesture.drag(&t, testDrag(&t, 1, 1, 10, 1));
@@ -1643,16 +1623,16 @@ test "SelectionGesture release clears autoscroll and records drag" {
}
test "SelectionGesture release with invalidated click records drag" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
try testing.expectEqual(false, gesture.left_click_dragged);
- _ = try t.screens.getInit(testing.allocator, .alternate, .{
+ _ = try t.screens.getInit(testing.io, testing.allocator, .alternate, .{
.cols = t.cols,
.rows = t.rows,
});
@@ -1664,13 +1644,13 @@ test "SelectionGesture release with invalidated click records drag" {
}
test "SelectionGesture same-cell threshold selection records drag" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
try testing.expectEqual(false, gesture.left_click_dragged);
@@ -1685,7 +1665,7 @@ test "SelectionGesture same-cell threshold selection records drag" {
}
test "SelectionGesture drag without press returns null" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
@@ -1696,13 +1676,13 @@ test "SelectionGesture drag without press returns null" {
}
test "SelectionGesture drag autoscroll edge boundaries" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
@@ -1720,13 +1700,13 @@ test "SelectionGesture drag autoscroll edge boundaries" {
}
test "SelectionGesture autoscroll tick scrolls and continues drag" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
@@ -1744,7 +1724,7 @@ test "SelectionGesture autoscroll tick scrolls and continues drag" {
}
test "SelectionGesture autoscroll tick resolves drag pin after scrolling" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 3, .max_scrollback = 10 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 3, .max_scrollback_bytes = 10 });
defer t.deinit(testing.allocator);
try t.printString("1111\n2222\n3333\n4444\n5555");
t.scrollViewport(.{ .delta = -2 });
@@ -1752,7 +1732,7 @@ test "SelectionGesture autoscroll tick resolves drag pin after scrolling" {
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
@@ -1773,20 +1753,20 @@ test "SelectionGesture autoscroll tick resolves drag pin after scrolling" {
}
test "SelectionGesture autoscroll tick stops with invalidated click" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
_ = gesture.drag(&t, testDrag(&t, 2, 1, 20, 1));
try testing.expectEqual(.up, gesture.left_drag_autoscroll);
- _ = try t.screens.getInit(testing.allocator, .alternate, .{
+ _ = try t.screens.getInit(testing.io, testing.allocator, .alternate, .{
.cols = t.cols,
.rows = t.rows,
});
@@ -1798,14 +1778,14 @@ test "SelectionGesture autoscroll tick stops with invalidated click" {
}
test "SelectionGesture deep press selects word and consumes drag" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 0, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 0, std.Io.Timestamp.now(testing.io, .awake)));
_ = gesture.drag(&t, testDrag(&t, 1, 0, 10, 1));
try testing.expectEqual(.up, gesture.left_drag_autoscroll);
@@ -1819,7 +1799,7 @@ test "SelectionGesture deep press selects word and consumes drag" {
false,
), sel);
try testing.expectEqual(@as(u3, 0), gesture.left_click_count);
- try testing.expectEqual(@as(?std.time.Instant, null), gesture.left_click_time);
+ try testing.expectEqual(@as(?std.Io.Timestamp, null), gesture.left_click_time);
try testing.expectEqual(true, gesture.left_click_dragged);
try testing.expectEqual(.none, gesture.left_drag_autoscroll);
try testing.expect(gesture.left_click_pin == null);
@@ -1830,20 +1810,20 @@ test "SelectionGesture deep press selects word and consumes drag" {
}
test "SelectionGesture drag with invalidated click returns null" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var press_event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var press_event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
press_event.xpos = 10;
_ = try gesture.press(&t, press_event);
_ = gesture.drag(&t, testDrag(&t, 2, 1, 20, 1));
try testing.expectEqual(.up, gesture.left_drag_autoscroll);
- _ = try t.screens.getInit(testing.allocator, .alternate, .{
+ _ = try t.screens.getInit(testing.io, testing.allocator, .alternate, .{
.cols = t.cols,
.rows = t.rows,
});
@@ -1854,14 +1834,14 @@ test "SelectionGesture drag with invalidated click returns null" {
}
test "SelectionGesture double-click drag selects by word" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta gamma");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
@@ -1877,14 +1857,14 @@ test "SelectionGesture double-click drag selects by word" {
}
test "SelectionGesture double-click drag selects by word backwards" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta gamma");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 7, 0, time));
_ = try gesture.press(&t, testPress(&t, 7, 0, time));
@@ -1900,14 +1880,14 @@ test "SelectionGesture double-click drag selects by word backwards" {
}
test "SelectionGesture double-click drag on empty cell selects nearest word" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
@@ -1923,14 +1903,14 @@ test "SelectionGesture double-click drag on empty cell selects nearest word" {
}
test "SelectionGesture triple-click drag selects by line" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta\none two\nthree four");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
_ = try gesture.press(&t, testPress(&t, 1, 0, time));
@@ -1945,14 +1925,14 @@ test "SelectionGesture triple-click drag selects by line" {
}
test "SelectionGesture triple-click drag selects by line backwards" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 20, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 20, .rows = 5 });
defer t.deinit(testing.allocator);
try t.printString("alpha beta\none two\nthree four");
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 2, 2, time));
_ = try gesture.press(&t, testPress(&t, 2, 2, time));
_ = try gesture.press(&t, testPress(&t, 2, 2, time));
@@ -1967,13 +1947,13 @@ test "SelectionGesture triple-click drag selects by line backwards" {
}
test "SelectionGesture repeat increments click count" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 1, time));
_ = try gesture.press(&t, testPress(&t, 1, 1, time));
@@ -1981,54 +1961,54 @@ test "SelectionGesture repeat increments click count" {
}
test "SelectionGesture repeat clamps at triple click" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
for (0..4) |_| _ = try gesture.press(&t, testPress(&t, 1, 1, time));
try testing.expectEqual(@as(u3, 3), gesture.left_click_count);
}
test "SelectionGesture null initial time stays single click" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
_ = try gesture.press(&t, testPress(&t, 1, 1, null));
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
try testing.expect(gesture.left_click_time != null);
}
test "SelectionGesture null repeat time stays single click" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
_ = try gesture.press(&t, testPress(&t, 1, 1, null));
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
- try testing.expectEqual(@as(?std.time.Instant, null), gesture.left_click_time);
+ try testing.expectEqual(@as(?std.Io.Timestamp, null), gesture.left_click_time);
}
test "SelectionGesture distant press resets click count" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, testPress(&t, 1, 1, time));
_ = try gesture.press(&t, testPress(&t, 4, 1, time));
@@ -2037,51 +2017,52 @@ test "SelectionGesture distant press resets click count" {
}
test "SelectionGesture expired repeat resets click count" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- var event = testPress(&t, 1, 1, try std.time.Instant.now());
+ var event = testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake));
event.repeat_interval = 0;
_ = try gesture.press(&t, event);
- std.Thread.sleep(std.time.ns_per_ms);
- event.time = try std.time.Instant.now();
+ try std.Io.sleep(testing.io, std.Io.Duration.fromMilliseconds(1), .awake);
+ event.time = std.Io.Timestamp.now(testing.io, .awake);
_ = try gesture.press(&t, event);
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
}
test "SelectionGesture backwards repeat time resets click count" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const earlier = testInstant(std.time.ns_per_s);
- const later = testInstant(2 * std.time.ns_per_s);
+ const now: std.Io.Timestamp = .now(testing.io, .awake);
+ const earlier = now.addDuration(.fromSeconds(1));
+ const later = now.addDuration(.fromSeconds(2));
_ = try gesture.press(&t, testPress(&t, 1, 1, later));
_ = try gesture.press(&t, testPress(&t, 1, 1, earlier));
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
- try testing.expectEqual(.eq, gesture.left_click_time.?.order(earlier));
+ try testing.expectEqualDeep(earlier, gesture.left_click_time.?);
}
test "SelectionGesture screen switch resets click count" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- const time = try std.time.Instant.now();
+ const time = std.Io.Timestamp.now(testing.io, .awake);
const primary_tracked = t.screens.active.pages.countTrackedPins();
_ = try gesture.press(&t, testPress(&t, 1, 1, time));
- _ = try t.screens.getInit(testing.allocator, .alternate, .{
+ _ = try t.screens.getInit(testing.io, testing.allocator, .alternate, .{
.cols = t.cols,
.rows = t.rows,
});
@@ -2094,34 +2075,34 @@ test "SelectionGesture screen switch resets click count" {
}
test "SelectionGesture removed screen resets without untracking stale pin" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
defer gesture.deinit(&t);
- _ = try t.screens.getInit(testing.allocator, .alternate, .{
+ _ = try t.screens.getInit(testing.io, testing.allocator, .alternate, .{
.cols = t.cols,
.rows = t.rows,
});
t.screens.switchTo(.alternate);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
t.screens.switchTo(.primary);
t.screens.remove(testing.allocator, .alternate);
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
try testing.expectEqual(@as(u3, 1), gesture.left_click_count);
try testing.expectEqual(.primary, gesture.left_click_screen);
}
test "SelectionGesture deinit untracks pin" {
- var t = try Terminal.init(testing.allocator, .{ .cols = 5, .rows = 5 });
+ var t = try Terminal.init(testing.io, testing.allocator, .{ .cols = 5, .rows = 5 });
defer t.deinit(testing.allocator);
var gesture: SelectionGesture = .init;
const tracked = t.screens.active.pages.countTrackedPins();
- _ = try gesture.press(&t, testPress(&t, 1, 1, try std.time.Instant.now()));
+ _ = try gesture.press(&t, testPress(&t, 1, 1, std.Io.Timestamp.now(testing.io, .awake)));
try testing.expectEqual(tracked + 1, t.screens.active.pages.countTrackedPins());
gesture.deinit(&t);