summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 45d96f88..91f0f9f4 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1531,6 +1531,16 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
p.update(.{ .key = .{ .cp = Key.escape } });
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0);
+ // The pane a letter offered is the one it answers for: unbound while
+ // the question stood, it is sent nothing, and that is said.
+ _ = exec.executeFrom(p, 0, "print(4)", true);
+ try std.testing.expect(p.executeBuiltinLine(2, "Repl -"));
+ p.update(.{ .key = .{ .cp = 'b' } });
+ Sent.drain(p);
+ try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0);
+ try std.testing.expectEqualStrings("Repl: the REPL chosen is gone; nothing sent", file.msg[0..file.msg_len]);
+ try std.testing.expect(p.executeBuiltinLine(2, "Repl python"));
+ try std.testing.expectEqualStrings("python-b", exec.replId(&idbuf, p.panes[2].?));
// A REPL whose program has left (Ctrl-D: the shell has the tty) is
// sent nothing, and nothing runs: it says so.
@@ -4152,7 +4162,9 @@ pub const Pardes = struct {
exec_depth: u8 = 0,
/// An exec waiting on the REPL question (`Pane.Prompt.repl_choice`):
/// the pane it came from, the language, and the text, owned.
- repl_ask: ?struct { from: u32, lang: u8, text: []u8 } = null,
+ /// `offered` holds, by letter, the serial of the pane each answer named
+ /// when asked: a letter answered later is that pane or nothing.
+ repl_ask: ?struct { from: u32, lang: u8, text: []u8, offered: [26]u32 = @splat(0) } = null,
/// A key press is being handled: someone is at the keyboard to answer,
/// so a builtin may ask rather than guess. Nothing else sets it -- not
/// a click, a 9P write, a startup line or a pane's shell exiting.
@@ -5261,9 +5273,14 @@ pub const Pardes = struct {
defer p.gpa.free(ask.text);
// Its letter sends it there; anything else takes it back.
if (key.ctrl or key.alt or key.cp > 'z' or key.cp < 'a') return;
- for (p.panes, 0..) |target, to| if (target) |repl| if (repl.repl) |r|
+ const serial = ask.offered[key.cp - 'a'];
+ if (serial == 0) return;
+ // The pane offered, still that REPL and still running: it
+ // may have closed or been rebound while the question stood.
+ if (p.paneBySerial(serial)) |to| if (p.panes[to].?.repl) |r|
if (r.lang == ask.lang and r.letter == key.cp and exec.replLive(p, to))
return exec.sendToRepl(p, id, to, ask.text);
+ p.setMessage(id, "Repl: the REPL chosen is gone; nothing sent");
return;
}
if (asked.prompt != .del_side) continue;