summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messages.zig33
-rw-r--r--core/TagState.zig32
-rw-r--r--core/tagline.zig7
3 files changed, 48 insertions, 24 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' } });
diff --git a/core/TagState.zig b/core/TagState.zig
index e4053f51..24d863bc 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -266,6 +266,32 @@ pub fn loaded(p: *Pardes) void {
};
}
+/// Asking (SPEC §3.2, §10.2): a question waiting on the pane, its tag at
+/// rest, in place of the tag's own text: what it asks, `▸`, each answer's
+/// key and word, and how to give one (`Esc later` while SPC e has given it
+/// the keyboard). The pane's state, not the view's keyboard: every view
+/// shows it; not while the tag has the keyboard, whose own text is edited
+/// then.
+fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
+ if (pane.focus == .tag or pane.prompt == .name) return null;
+ const i = p.messages.waiting(pane) orelse return null;
+ const said = &p.messages.live[i];
+ var b: Builder = .{ .arena = arena };
+ try b.put(" ");
+ try b.put(said.words());
+ try b.put(" ");
+ try b.styled("▸", .key);
+ for (said.asks.answers()) |a| {
+ try b.put(" ");
+ try b.styled(&.{a.key}, .key);
+ try b.put(" ");
+ try b.put(a.word);
+ try b.put(" ");
+ }
+ try b.styled(if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer", .dim);
+ return b.done();
+}
+
/// The last leaf run in the current level, as the line under it says it
/// (Messages' leader band): `k Hover: its summary (last used here)`, while
/// the level is shown rolled.
@@ -441,10 +467,10 @@ const Builder = struct {
};
/// The head of pane `pane`'s tag while it is out of rest in the live view,
-/// null at rest.
+/// or while a question waits on it at rest (`asking`); null at rest.
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
- const id = hostOf(p) orelse return null;
- if (p.panes[id] != pane) return null;
+ const id = hostOf(p) orelse return asking(p, arena, pane);
+ if (p.panes[id] != pane) return asking(p, arena, pane);
const v = p.view();
const s = &v.tag_state;
var b: Builder = .{ .arena = arena };
diff --git a/core/tagline.zig b/core/tagline.zig
index 9e9b9757..78d5a256 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -220,12 +220,7 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 {
/// The prefix as the tag shows it, built in `arena`.
pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 {
- const path = try pathPrefix(p, arena, pane);
- // Asking (SPEC §3.2): a question waiting on it, after the path while
- // the tag is at rest (not while it has the keyboard).
- var asking: [512]u8 = undefined;
- const asks = if (pane.focus == .tag or pane.prompt == .name) "" else p.messages.askingText(pane, p.view().answering == pane.serial, &asking);
- const prefix = if (asks.len > 0) try std.mem.concat(arena, u8, &.{ path, " ", asks }) else path;
+ const prefix = try pathPrefix(p, arena, pane);
// The space between the prefix and the tag's own text is the text's
// (every default starts with one), but the prefix is computed, so it
// cannot trust the text to keep it: with it deleted, Look and Exec