summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 11:10:32 -0300
committerGabriel Schneider <[email protected]>2026-10-29 14:30:01 -0300
commite91a3788752c63c2ed086c553f9861056172e8c0 (patch)
tree2ce56163ac525b6772737a0cbc44ae5deb3c08d4
parent97f83717cf8be3e4eedd3f7b932766c1cf72fd37 (diff)
downloadpardes-e91a3788752c63c2ed086c553f9861056172e8c0.tar.gz
pardes-e91a3788752c63c2ed086c553f9861056172e8c0.zip
tty: a pane flooded with output (`yes`) is read on to its end, not left blocked for good while keys still work
vaxis's event queue woke one blocked writer, and only on the pop from full. The tty's loop has two writers on it: a pane's pty reader, and the input reader posting the wake for a frame's answered status request (FrameAck). Under `yes` both block on the full queue; the loop then takes a whole batch, its first pop wakes one of them, the rest wake no one, and the pty reader waits for good: the program in the pane blocks writing to its pty, the pane stops moving, and every key still works. It happened from about 400 KB of output, every time at 1 MB, through the snapshot harness's pty as through a terminal. build.zig patches vaxis's src/queue.zig at build time, count-checked as its Parser.zig and Vaxis.zig are: a pop that makes room wakes every blocked writer. A test (src/vaxis_input.zig) empties a full queue in one batch with two writers waiting and requires both to land. `yes | head -c N` through a bash pane in tty mode now finishes at 1 MB, 10 MB, 100 MB (16 s) and 1 GB (179 s, test/perf.zig --live). Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--build.zig18
-rw-r--r--src/vaxis_input.zig31
2 files changed, 46 insertions, 3 deletions
diff --git a/build.zig b/build.zig
index 9515e536..5e337dfc 100644
--- a/build.zig
+++ b/build.zig
@@ -888,13 +888,25 @@ pub fn build(b: *std.Build) void {
\\}
\\
;
+ // And its event queue: a pop that makes room woke one blocked
+ // writer, and only on the pop from full. The tty has two writers
+ // (a pane's pty reader, and the input reader posting the frame
+ // ack's wake), so when the loop emptied a full queue in one batch
+ // the writer not woken waited on for good: under `yes` the pane
+ // stopped being read, its program blocked on the pty, while keys
+ // went on working. Every blocked writer is woken now.
+ var queue_src = configureRead(b, io, vaxis_dep.builder.root, "src/queue.zig", 1 << 20) catch @panic("read vaxis queue.zig");
+ const wake_one = "self.not_full.signal(self.io);";
+ if (std.mem.count(u8, queue_src, wake_one) != 2) std.debug.panic("vaxis's queue.zig changed at `{s}`: redo its patch in build.zig", .{wake_one});
+ queue_src = std.mem.replaceOwned(u8, b.allocator, queue_src, wake_one, "self.not_full.broadcast(self.io); // pardes's patch (its build.zig)") catch @panic("OOM");
const files = b.addWriteFiles();
_ = files.add("Parser.zig", b.fmt("{s}{s}", .{ src, cursor_report }));
_ = files.add("Vaxis.zig", b.fmt("{s}{s}", .{ render_src, blank_ink }));
+ _ = files.add("queue.zig", queue_src);
_ = files.addCopyFile(vaxis_dep.path("src/widgets/terminal/Parser.zig"), "widgets/terminal/Parser.zig");
- // Suffixes: this leaves out both Parser.zig files and Vaxis.zig,
- // written above.
- _ = files.addCopyDirectory(vaxis_dep.path("src"), "", .{ .exclude_extensions = &.{ "Parser.zig", "Vaxis.zig" } });
+ // Suffixes: this leaves out both Parser.zig files, Vaxis.zig and
+ // queue.zig, written above.
+ _ = files.addCopyDirectory(vaxis_dep.path("src"), "", .{ .exclude_extensions = &.{ "Parser.zig", "Vaxis.zig", "queue.zig" } });
vaxis_mod.root_source_file = files.getDirectory().path(b, "main.zig");
}
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);
+}