summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig40
1 files changed, 40 insertions, 0 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 6b406e91..53d2951b 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -544,6 +544,46 @@ pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_row
return n;
}
+// ---- a stand-in for line C's questions (walk UI; C's change vxmpyyst) ----
+//
+// `:` lists the answers of a question waiting on its pane first (pick-ui
+// SPEC ยง10.4, Command.zig). This tree has no such questions, and these say
+// none: THE MERGE with C's line deletes this block, to its end marker, and
+// keeps C's `Answer`, `waiting`, `waitingAnswers` and `answer`, whose
+// shapes these are. `stub_asked` lets Command.zig's test ask one here.
+
+/// A question's answer: the key that gives it and its word.
+pub const Answer = struct { key: u8, word: []const u8 };
+
+/// The question waiting on `pane`, an index of the live ones: none.
+pub fn waiting(m: *const Messages, pane: *const Pane) ?usize {
+ _ = m;
+ return if (@import("builtin").is_test and stub_asked != 0 and stub_asked == pane.serial) 0 else null;
+}
+
+/// The answers of the question waiting on `pane`: none.
+pub fn waitingAnswers(m: *const Messages, pane: *const Pane) []const Answer {
+ return if (m.waiting(pane) != null) &stub_answers else &.{};
+}
+
+/// Answer live question `i` with `key`: false for a key that is none of
+/// its answers.
+pub fn answer(p: *Pardes, i: usize, key: u8) bool {
+ _ = p;
+ _ = i;
+ for (stub_answers) |a| if (a.key == key) {
+ stub_asked = 0;
+ return true;
+ };
+ return false;
+}
+
+/// A test's question: the serial of the pane it waits on.
+pub var stub_asked: u32 = 0;
+const stub_answers = [_]Answer{ .{ .key = 'r', .word = "Reload" }, .{ .key = 'k', .word = "Keep mine" }, .{ .key = 'd', .word = "Diff" } };
+
+// ---- the stand-in's end ----
+
test "errors are said in words, and a ZON failure names its line" {
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings("file not found", errorWords(error.FileNotFound, &buf));