summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 22:14:32 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commit754ffc99799c3a251634c1eff9a16eabbd73b31c (patch)
tree92125a9cce020848038285842c1665d0bd4a0ba6 /src
parent28d11d18a739864406a37a9b2c6f3fefc450b6bc (diff)
downloadpardes-754ffc99799c3a251634c1eff9a16eabbd73b31c.tar.gz
pardes-754ffc99799c3a251634c1eff9a16eabbd73b31c.zip
A Python block sent to a REPL gets the second Enter that ends it
A dogfood agent's `def` sent to python3 sat open at the continuation prompt: a block whose last line is indented is not over at one Enter, pasted into 3.13's REPL or typed into the old one (checked against python 3.14 in a real pty, both ways). A send to a Python REPL now adds that second Enter, and the pty/data recipe in the docs and the 9P skill says to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/exec.zig12
-rw-r--r--src/pardes.zig5
2 files changed, 17 insertions, 0 deletions
diff --git a/src/exec.zig b/src/exec.zig
index 1e9d4b2d..0c0930e2 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -464,6 +464,13 @@ fn routeToRepl(p: *Pardes, from: usize, text: []const u8) Routed {
return .asked;
}
+fn pythonBlockOpen(text: []const u8) bool {
+ const trimmed = std.mem.trimEnd(u8, text, " \t\n");
+ const start = if (std.mem.lastIndexOfScalar(u8, trimmed, '\n')) |nl| nl + 1 else 0;
+ const last = trimmed[start..];
+ return last.len > 0 and (last[0] == ' ' or last[0] == '\t' or last[last.len - 1] == ':');
+}
+
/// Types `text` into the REPL in `to`, bracketed if its program asked for
/// that, then Enter; says so on `from`'s message row and in the log.
pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
@@ -491,6 +498,11 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
}
edit.typeToTty(p, to, dst, clean[0..n]);
p.emitWrite(to, "\r");
+ // A Python block whose last line is indented, or a bare header, is not
+ // over at one Enter, pasted into 3.13's REPL or typed into the old one:
+ // the blank line a second Enter gives ends it.
+ if ((if (dst.repl) |r| r.lang == python_lang else false) and pythonBlockOpen(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 (if (dst.repl) |r| r.lang == python_lang else false) and
std.mem.indexOfScalar(u8, text, '\n') != null)
diff --git a/src/pardes.zig b/src/pardes.zig
index 239987ea..e20eb17e 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1474,6 +1474,11 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
_ = exec.executeFrom(p, 0, "a = 1\r\nb = \x1b[201~2", true);
Sent.drain(p);
try std.testing.expectEqualStrings("a = 1\rb = [201~2\r", Sent.said(1));
+ // A block left open by its indented last line gets the blank line that
+ // ends it: a second Enter.
+ _ = exec.executeFrom(p, 0, "def f():\n return 1", true);
+ Sent.drain(p);
+ try std.testing.expectEqualStrings("def f():\r return 1\r\r", Sent.said(1));
// Several selections executed at once: each is sent, not the first.
{
const text = try edit.flatSurface(p, &file.body);