summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pardes.zig12
1 files changed, 12 insertions, 0 deletions
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 <serial> <choice|->`, 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,