diff options
| -rw-r--r-- | src/Core.zig | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/Core.zig b/src/Core.zig index 65779217..d09c1188 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -889,7 +889,10 @@ pub fn writeRoom(p: *const Pardes, id: usize) usize { } pub fn parkPendingWrite(p: *Pardes, id: usize, bytes: []const u8) void { - if (p.pending_write_bytes + bytes.len > limits.pending_write_cap) return; + if (p.pending_write_bytes + bytes.len > limits.pending_write_cap) { + var said: [128]u8 = undefined; + return p.setMessage(id, std.fmt.bufPrint(&said, "write: {d} bytes for the program dropped, past the {d} MiB that may wait for it", .{ bytes.len, limits.pending_write_cap >> 20 }) catch unreachable); // two numbers fit 128 + } if (p.pending_write[id]) |*pw| { // Compact what the drain already sent before growing: a burst that // arrives in pieces must not keep re-copying bytes nobody wants. @@ -3812,6 +3815,21 @@ test "a paste larger than the effect ring reaches the program whole and in order try std.testing.expectEqual(@as(usize, 0), p.pending_write_bytes); } +test "bytes for a terminal past what may wait for it are dropped and said, never silently" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + // Past the ring's room and the cap of what may wait behind it. + const big = try gpa.alloc(u8, p.writeRoom(0) + (1 << 20)); + defer gpa.free(big); + @memset(big, 'z'); + p.emitWrite(0, big); + try std.testing.expectEqual(@as(usize, 0), p.pending_write_bytes); + const pane = p.panes[0].?; + try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "dropped") != null); +} + test "a bracketed paste larger than the ring still closes its bracket" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); |
