summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pardes.zig40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 0dc0dc5f..f637e78a 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7312,13 +7312,11 @@ pub const Pardes = struct {
pane.clearPointerSelection(sel_slot);
pane.sel[sel_slot].state = .none;
}
+ // What the terminal answers its program (a cursor report, its
+ // attributes) goes as typed bytes go: behind whatever is still
+ // queued for its pty, never ahead of it nor dropped.
if (comptime terminal_panes) if (pane.terminal) |state| {
- var off: u16 = 0;
- while (off < state.reply_len) {
- const n = @min(state.reply_len - off, 64);
- p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(state.reply[off .. off + n]) } });
- off += n;
- }
+ p.emitWrite(id, state.reply[0..state.reply_len]);
state.reply_len = 0;
};
const r = p.rects[id];
@@ -7414,7 +7412,7 @@ pub const Pardes = struct {
.never => pane.greet = false,
.now => {
p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = pane.cols, .rows = pane.rows } });
- p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from("ls\r") } });
+ p.emitWrite(id, "ls\r");
pane.greet = false;
},
};
@@ -8444,6 +8442,34 @@ test "a bracketed paste larger than the ring still closes its bracket" {
try std.testing.expectEqualSlices(u8, text, got["\x1b[200~".len .. got.len - "\x1b[201~".len]);
}
+test "a terminal's answer to its program waits behind the paste still queued for its pty" {
+ if (platform == .web) return;
+ if (comptime !panes.terminal.enabled) return;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
+ const buf = try gpa.alloc(u8, 1 << 20);
+ defer gpa.free(buf);
+ _ = drainWrites(p, buf);
+ panes.terminal.enterTty(p, 0);
+
+ const text = try gpa.alloc(u8, 300 * 1024);
+ defer gpa.free(text);
+ @memset(text, 'p');
+ p.update(.{ .paste = text });
+ // The ring is full and the rest of the paste waits for room in it. A
+ // host takes one write off, and the program asks where its cursor is.
+ const taken = p.nextEffect().?;
+ const off = if (taken == .write) taken.write.bytes.len else 0;
+ p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[6n" } });
+ const got = drainWrites(p, buf);
+ // The whole paste first, then the answer, `CSI row ; col R`, whole.
+ try std.testing.expectEqualSlices(u8, text[off..], got[0 .. text.len - off]);
+ const answer = got[text.len - off ..];
+ try std.testing.expect(std.mem.startsWith(u8, answer, "\x1b[") and std.mem.endsWith(u8, answer, "R"));
+}
+
test "pasted bytes still queued at shutdown are freed, not leaked" {
if (platform == .web) return;
const gpa = std.testing.allocator;