From 5b5896965758ff8f2077c8e8e2f0250f580967c3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 01:48:39 -0300 Subject: Every answer to a pane's question is logged, answer - included The log said ask but never what came of it, so a follower could not tell a question taken back from one still standing. answerQuestion now records answer whichever route answered, key or ctl; a key the question does not offer is -. (Docs are in the tagexec change.) Co-Authored-By: Claude Opus 5.5 --- src/pardes.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 54fe2df0..706e9ef3 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1712,6 +1712,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe const answered = th.wr(p, ctlfs.Node.of(file.serial, .ctl), "answer a\n"); try std.testing.expectEqual(ctlfs.Status.ok, answered.reply.status); try std.testing.expectEqualStrings("print(5)\r", answered.pty()); + try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} a\n", .{file.serial}))); } _ = exec.executeFrom(p, 0, "print(3)", true); p.update(.{ .key = .{ .cp = Key.escape } }); @@ -5573,8 +5574,17 @@ pub const Pardes = struct { } } + /// Answers the pane's question: a choice it offers, else (null, or a + /// key it does not offer) takes it back. The log says which, as + /// `answer `, after the `ask` it answers. pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool { const asked = p.panes[id] orelse return false; + var offered: [64]u8 = undefined; + if (p.questionChoices(id, &offered)) |choices| { + const chosen: ?u8 = if (choice) |c| (if (std.mem.indexOfScalar(u8, choices, c) != null and c != ' ') c else null) else null; + var rec: [32]u8 = undefined; + ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {c}", .{ asked.serial, chosen orelse '-' }) catch ""); + } switch (asked.prompt) { .repl_choice => { asked.prompt = .none; @@ -7085,10 +7095,12 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[asked].?.prompt); try std.testing.expectEqual(ctlfs.Status.ok, th.wr(p, ctl, "answer -\n").reply.status); try std.testing.expect(p.panes[asked] != null and p.panes[asked].?.prompt == .none); + try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} -\n", .{serial}))); p.update(.{ .key = .{ .cp = ' ' } }); p.update(.{ .key = .{ .cp = 'd' } }); try std.testing.expectEqual(ctlfs.Status.ok, th.wr(p, ctl, "answer k\n").reply.status); try std.testing.expect(p.paneBySerial(serial) == null); + try std.testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "answer {d} k\n", .{serial}))); } // Bare Del from anything but a key closes at once and gives the rows up, -- cgit v1.3