summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 20:45:42 -0300
committerGabriel Schneider <[email protected]>2026-11-08 21:48:19 -0300
commitd31cc9eb97da97e3cb5268565ced3bf8c25f8540 (patch)
tree595dba9ef28752b3a1f37cf33229fdc153215362 /src/terminal.zig
parentc35251904681f3a195a6ede71dba235463b0e962 (diff)
downloadpardes-d31cc9eb97da97e3cb5268565ced3bf8c25f8540.tar.gz
pardes-d31cc9eb97da97e3cb5268565ced3bf8c25f8540.zip
fix: a raw terminal's key whose text passed forwardKey's 256-byte buffer (an input method's commit, a paste as one key) was dropped with no word: the encoding grows past the stack's room onto the heap and goes out through emitWrite, cut into writes in order; a failure to grow is reported; a pane test forwards 1000 bytes of key text and reads them back whole
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index 5338afa7..16ffb34b 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -1616,9 +1616,14 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
utf8[0 .. std.unicode.utf8Encode(text_cp, &utf8) catch return]
else
"";
- var buffer: [256]u8 = undefined;
- var writer = std.Io.Writer.fixed(&buffer);
- input.encodeKey(&writer, .{
+ // A key's text has no bound of its own (an input method's commit, a
+ // paste as one key): past the stack's room the encoding grows on the
+ // heap, and emitWrite cuts it into writes.
+ var room: [256]u8 = undefined;
+ var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa);
+ var out: std.Io.Writer.Allocating = .init(first.allocator());
+ defer out.deinit();
+ input.encodeKey(&out.writer, .{
.key = physical,
.mods = .{ .ctrl = key.ctrl, .alt = key.alt, .shift = key.shift },
.consumed_mods = .{ .shift = key.text.len > 0 and key.shift },
@@ -1637,8 +1642,8 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
// the floor and forwards Alt-n to the child as a bare `n`.
opts.macos_option_as_alt = .true;
break :options opts;
- }) catch return;
- if (writer.end > 0) p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(writer.buffered()) } });
+ }) catch |err| return p.reportError(id, "key", err);
+ if (out.written().len > 0) p.emitWrite(id, out.written());
}
pub fn enterTty(p: *Pardes, id: usize) void {