diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 8ecf2919..7cee0d25 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -485,19 +485,6 @@ pub fn waitingAnswers(m: *const Messages, pane: *const Pane) []const Answer { return m.live[i].asks.answers(); } -/// The waiting question's words as its pane's tag asks them, while the tag -/// is at rest (SPEC ยง3.2 asking): what it asks, its answers, and how to -/// give one. `answering`: SPC e gave it the keyboard. -pub fn askingText(m: *const Messages, pane: *const Pane, answering: bool, out: []u8) []const u8 { - const i = m.waiting(pane) orelse return ""; - const s = &m.live[i]; - var w: std.Io.Writer = .fixed(out); - w.print("{s} \u{25b8}", .{s.words()}) catch {}; - for (s.asks.answers()) |a| w.print(" {c} {s} ", .{ a.key, a.word }) catch {}; - w.writeAll(if (answering) "\u{b7} Esc later" else "\u{b7} SPC e to answer") catch {}; - return w.buffered(); -} - /// Answer live question `i` with `key`: `r` reads the file again over its /// unsaved text, `k` keeps the text and lets the disk's be, `d` shows (or /// hides again) the disk's lines where they differ, as ghosts in its @@ -1318,9 +1305,25 @@ test "a file changed on disk under unsaved text asks in its tag and never takes p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } }); const i = p.messages.waiting(pane) orelse return error.NotAsked; try std.testing.expectEqual(Kind.question, p.messages.live[i].kind); - // In its tag at rest, its answers offered; its mark `?`. + // In its tag at rest, its answers offered in place of the tag's own + // words (the head, walk UI R1), read-only; its mark `?`. + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const shown = try pardes.tagline.tagText(p, frame.allocator(), pane); + try std.testing.expect(std.mem.endsWith(u8, shown, " changed on disk \u{25b8} r Reload k Keep mine d Diff \u{b7} SPC e to answer")); + try std.testing.expect(std.mem.startsWith(u8, shown, path)); + try std.testing.expectEqual(Kind.question, p.messages.markOf(pane).?); + try std.testing.expect(std.mem.indexOf(u8, shown, "Save") == null); const prefix = try pardes.tagline.tagPrefix(p, pane); - try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk \u{25b8} r Reload k Keep mine d Diff \u{b7} SPC e to answer") != null); + try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk") == null); + // The tag's own text is no one's to edit meanwhile. + try std.testing.expect((try pardes.TagState.head(p, frame.allocator(), pane)) != null); + // Out of rest (SPC: its key cell at once) the level's head, not the + // question; at rest again, the question. + p.update(.{ .key = .{ .cp = ' ' } }); + try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") == null); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") != null); try std.testing.expectEqualStrings("Reload", p.messages.waitingAnswers(pane)[0].word); // The keyboard is not its: `r` is the body's (helix's replace). p.update(.{ .key = .{ .cp = 'k' } }); |
