summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 16:34:52 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commitb586d916c2aac1e5e577162898ebb86632f32db0 (patch)
treeac109d93e28c478ec7b596bef1d5ae7664f2ec75 /src/exec.zig
parentf30ee05b0609b8f3aa488c94f3ff21733ed37053 (diff)
downloadpardes-b586d916c2aac1e5e577162898ebb86632f32db0.tar.gz
pardes-b586d916c2aac1e5e577162898ebb86632f32db0.zip
Text sent to a REPL is plain lines, sent whole or not at all
A CRLF became two line ends, the blank line ending a Python block; an ESC in the text, ESC[201~ above all, could end a bracketed paste early; and on the board, whose writes are 128 effects of 64 bytes with nothing pending, a send past 8 KB was cut and lost its closing ESC[201~ and Enter, leaving the REPL in a paste. Lines now end in LF alone, ESC and every control byte but tab and newline are dropped, and a send larger than can be written at once (Pardes.writeRoom) is refused with a message instead of cut. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/exec.zig b/src/exec.zig
index cd2b4089..7f2e0e1f 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -471,7 +471,25 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
const src = p.panes[from] orelse return;
var idbuf: [48]u8 = undefined;
const id = replId(&idbuf, dst);
- edit.typeToTty(p, to, dst, text);
+ // Lines end in \n alone (a \r\n would give Python a blank line that
+ // ends its block), and no ESC or other control byte but a tab goes: an
+ // ESC[201~ in the text would end a bracketed paste early.
+ const clean = p.scratch.allocator().alloc(u8, text.len) catch return;
+ var n: usize = 0;
+ for (text, 0..) |c, i| {
+ if (c == '\r') {
+ if (i + 1 < text.len and text[i + 1] == '\n') continue;
+ clean[n] = '\n';
+ } else if (c < ' ' and c != '\t' and c != '\n' or c == 0x7f) continue else clean[n] = c;
+ n += 1;
+ }
+ // Sent whole or not at all: a send cut short would leave the REPL in a
+ // paste, or with half a block.
+ if (n + 16 > p.writeRoom(to)) {
+ var said: [128]u8 = undefined;
+ return p.setMessage(from, std.fmt.bufPrint(&said, "Repl: {d} bytes is more than can be sent at once; send less", .{n}) catch "Repl: too long to send");
+ }
+ edit.typeToTty(p, to, dst, clean[0..n]);
p.emitWrite(to, "\r");
// Line by line, a blank line inside a Python block ends the block.
if (!panes.Terminal.bracketedPaste(dst) and !dst.repl_warned and std.mem.startsWith(u8, id, "python") and