summaryrefslogtreecommitdiff
path: root/src/vaxis_input.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
committerGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
commita479792a1ab2b593642d7f648194bfa23ce01dba (patch)
tree96ddee7d879a9084daa07db43b0b7910b072a785 /src/vaxis_input.zig
parente179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff)
parent4c761893e5b3fdae422622cfa02104ab36633045 (diff)
downloadpardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz
pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/vaxis_input.zig')
-rw-r--r--src/vaxis_input.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/vaxis_input.zig b/src/vaxis_input.zig
index 0e25dea1..59846d0f 100644
--- a/src/vaxis_input.zig
+++ b/src/vaxis_input.zig
@@ -75,3 +75,34 @@ test "F-keys, Insert and the keypad map to the core's keys" {
try std.testing.expectEqual(pardes.Key.enter, keyEvent(.{ .codepoint = vaxis.Key.kp_enter }).key.cp);
try std.testing.expectEqual(@as(u21, 'a'), mapKey('a'));
}
+
+test "an event queue emptied in one batch lets every writer it held go on (build.zig's patch)" {
+ const io = std.testing.io;
+ const Q = vaxis.Queue(u8, 2);
+ var q: Q = .init(io);
+ try q.push(1);
+ try q.push(2);
+ const Writer = struct {
+ fn run(queue: *Q, byte: u8) !void {
+ try queue.push(byte);
+ }
+ };
+ // Two writers waiting on the full queue, as a pane's pty reader and
+ // the frame ack's wake do under `yes`.
+ var a = try io.concurrent(Writer.run, .{ &q, 3 });
+ defer a.cancel(io) catch {};
+ var b = try io.concurrent(Writer.run, .{ &q, 4 });
+ defer b.cancel(io) catch {};
+ try io.sleep(.fromMilliseconds(20), .awake);
+ // The loop takes both at once: one pop from full, then one more.
+ try q.lock();
+ _ = q.drain().?;
+ _ = q.drain().?;
+ q.unlock();
+ var got: usize = 0;
+ var waited: usize = 0;
+ while (got < 2 and waited < 200) : (waited += 1) {
+ if (try q.tryPop() != null) got += 1 else try io.sleep(.fromMilliseconds(5), .awake);
+ }
+ try std.testing.expectEqual(@as(usize, 2), got);
+}