summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 12:44:35 -0300
committerGabriel Schneider <[email protected]>2026-11-26 13:02:49 -0300
commit51f211d694beff9a389ab519f2286cef077adb81 (patch)
tree2df93ee551f2820011f6f67b32f5131fbd927888 /core
parent3d60aa05ec1a6f9ed535186be6c6c2850c71b24d (diff)
parentd7b01dfc187244b6613a954d82552675d3bd2689 (diff)
downloadpardes-51f211d694beff9a389ab519f2286cef077adb81.tar.gz
pardes-51f211d694beff9a389ab519f2286cef077adb81.zip
merge (M3): tonplrtr 3d60aa05ec1a (L2a: the tags, grips, band and notice row drawn from the chrome, the old ChromeTheme, Roles and Grounds views deleted, part H's inks, the path dim while a pane previews another file; M2's wxvzvomn, dump.load resolves the chrome; FP's PDF preview leak, the exec rerun's spawn stop, ABI 3.4's PDF hits) with rppqvrqx d7b01dfc1872 (W9, walkui UX DESIGN part O on W5's part M: the tag stays at rest and the head hangs under it as the band's first row, a picker hangs under the tag of the pane with the keyboard, the mouse never ends it, TagState.waits, Pick.tall, the act/source row gone), resolved: THE CODE: core/draw.zig joinBand draws W5/W9's layout with L2a's inks: the head (TagState.head) and the band from `p.chrome().on(focus or plain)` (its keys `inks.key`, its error `inks.severity[0]`, its dim and rule the ground's), the band's rows' keys, chords, `pre` (the name tint `chrome.name[g]`), dim, kind and matched letters as L2a drew them, W9's loop variable `i` kept; paintPaneTag keeps W9's question in the tag (TagState.asking) and L2a's single tag ink (W9's out-of-rest `text_style` gone with L2a's: a question's text and the tag's own were the same ink once Roles went), and draws the computed words in the words' ink whenever the tag does not ask (L2a's `head == null and !asks`: out of rest the tag is the rest tag now, so its words are the rest words); render's head-and-band gutter (W9's `at.tag`) on L2a's ground; draw's key-ink test reads `p.chrome().on(.focus)` and W9's `? help`; core/TagState.zig's W5 test "out of rest a tag is drawn as at rest ..." (renamed: "... but the box and its path's ink, the path its own and dim ...") lets the path's cells differ in their ink alone, the dim ink, the dimmed text ending `/far.txt`: L2a's zrxurkop dims a tag's path while its body previews another file (the coordinator's ruling, UX DESIGN M7.2), which the test, written before it on W5's tree, read as a moved cell (core-test failed it at TagState.zig:1741 on the merge as jj made it); THE GOLDENS: process-test -- --update re-recorded all 103 golden cases, the 102 golden files (every one with a frame out of rest among them), and moved exactly the two in conflict, fsearch and selregex, each now W9's text rows byte for byte (gdiff.py: no snap row differs from W9's) and L2a's inks on them; read cell by cell (.scratch/walkui/M3/gpairs.py: each cell where the merge differs from W9's recording, and whether L2a made that same move base -> L2a): selregex's four style blocks and fsearch's one move only by L2a's classes: the window and column rows to the page (#b2c3b8 on #1d2824 -> #788079 on #0d1410, the active column's #becfc4 on #314738 too), the reading pane's tint #2c2c0f gone to the focus ground #394440 under the rest tag (full ink #becfc4 -> #cadbd0, the name tint #ecc8f2 kept, its computed words and the blanks after them #becfc4 -> #a1b1a8, the word ink) and under the head on the row below it (text #cadbd0, keys #bada9d -> #add38a bold, dim #79836f -> #8e9d94), a focused reading grip's glyph #000000 -> mode_glyph #06779d, the rail's current tick to the current hit #917a53, a command pane's computed words #b2c3b8 -> #819188; the only pairs L2a's own recordings never made are the same ink moves on cells W9 newly drew there: the head row's gutter cells on the tag's ground (`d` and the body's #e5eee5 on #2c2c0f -> #394440: render's gutter fill on L2a's ground), and fsearch's rest tag on the reading pane W9 moved to row 16 (name tint and words as selregex's); no row neither side explains; the 100 other golden files re-recorded byte for byte as the merge had them (L2a's 36 as L2a recorded them, W9's six text-only goldens as W9 did); GATES (Debug tui, on this change): core-test 1163/1338 (175 skipped; L2a's tree 1160/1335, W9's three new tests), shell-test 1386/1389 (3 skipped), process-test 0 of 103 failed with --update (2 moved, read above); the rest of the gates on the stack's top; load 1.2 to 2.5
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig99
-rw-r--r--core/Command.zig58
-rw-r--r--core/Core.zig15
-rw-r--r--core/Messages.zig9
-rw-r--r--core/Pick.zig512
-rw-r--r--core/Prompt.zig96
-rw-r--r--core/Query.zig2
-rw-r--r--core/TagState.zig303
-rw-r--r--core/Trail.zig99
-rw-r--r--core/bindings.zig10
-rw-r--r--core/body_layer.zig12
-rw-r--r--core/draw.zig174
-rw-r--r--core/edit.zig4
-rw-r--r--core/exec.zig7
-rw-r--r--core/keys.zig16
-rw-r--r--core/layout.zig47
-rw-r--r--core/lsp/Ask.zig6
-rw-r--r--core/mouse.zig371
-rw-r--r--core/panes.zig3
-rw-r--r--core/tagline.zig121
-rw-r--r--core/views.zig10
21 files changed, 1401 insertions, 573 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 228dcad0..23618fda 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -1,10 +1,11 @@
//! The band (walk UI, pick-ui SPEC.md §3.6): rows hanging under a pane's
-//! tag while it is out of rest, in the tag's tint, drawn over the top rows
-//! of its body, which stay where they were (UX DESIGN I1): the tag
-//! unrolled. Its steps stand side by side, each a column of rows
-//! (a level, Help's rows, a doc; later a picker's acts and sources, a
-//! prompt's history, the registers), a one-cell rule between them, right
-//! of a spine under each of the head's key cells.
+//! head (TagState.head, the row under its tag) while it is out of rest, in
+//! the tag's tint, drawn over the top rows of its body, which stay where
+//! they were (UX DESIGN I1, M2): the tag unrolled. Its steps stand side by
+//! side, each a column of rows (a level, Help's rows, a doc; later a
+//! picker's acts and sources, a prompt's history, the registers), a
+//! one-cell rule between them, right of a spine under each of the head's
+//! key cells.
//!
//! Derived from the live view's state each time it is asked (`of`), never
//! stored (the coordinator's R2): the layout reads its height (`takes`,
@@ -136,24 +137,25 @@ pub fn takes(p: *Pardes, id: usize) u16 {
return @max(doc_rows, levelRows(n));
}
-/// Where pane `id`'s tag out of rest is drawn, in rows from its top (UX
-/// DESIGN I1): its head's text (`text`, the rows its own text keeps from
-/// rest at least where no band hangs under it) and the band under that
-/// (`band`), as many as the pane has; `over` of them past the tag's own
-/// rows (`tag_rows`, its rows at rest), drawn over the top rows of its
-/// body, which never move for them. A picker's band keeps a body of
-/// `body_rows` under it (UX D6), any other state only the pane's rows.
-/// Asked of the state alone, as `takes` is: the layout, the frame and a
-/// click ask it of the same step.
-pub const Covered = struct { text: u16, band: u16, over: u16 };
+/// Where pane `id`'s head and band hang out of rest, in rows from its top
+/// (UX DESIGN I1, M2): under its tag's rows (`tag`, its rows at rest, which
+/// no state changes), its head's (`head`), then the band's (`band`), as
+/// many as the pane has under its tag; `over` the two, drawn over the top
+/// rows of its body, which never move for them. A picker's band over the
+/// pane its preview shows in keeps a body of `body_rows` under it (UX D6,
+/// DESIGN O1), any other only the pane's rows. Asked of the state alone, as `takes` is: the layout, the frame and
+/// a click ask it of the same step.
+pub const Covered = struct { tag: u16, head: u16, band: u16, over: u16 };
pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered {
- if (pane.collapsed or TagState.hostOf(p) != id) return .{ .text = pane.tag_rows, .band = 0, .over = 0 };
+ if (pane.collapsed or TagState.hostOf(p) != id) return .{ .tag = pane.tag_rows, .head = 0, .band = 0, .over = 0 };
const h = p.view().rects[id].h;
- const text = @min(layout.headRows(p, id), h);
- const keep: u16 = if (p.view().tag_state.kind == .pick) body_rows else 0;
- const band = @min(takes(p, id), h -| text -| keep);
- const shown = if (band > 0) text else @min(@max(text, pane.tag_rows), pardes.MAX_TAG_ROWS);
- return .{ .text = shown, .band = band, .over = (shown + band) -| pane.tag_rows };
+ // As Pardes.sync sets `tag_rows` (a picker's preview adds the rows
+ // over it to them).
+ const tag = @min(layout.wantedTagRows(p, id), pardes.MAX_TAG_ROWS, @max(pardes.BOX_H, h -| 1));
+ const head = @min(layout.headRows(p, id), h -| tag);
+ const keep: u16 = if (@import("Pick.zig").previewPane(p, id)) body_rows else 0;
+ const band = @min(takes(p, id), h -| tag -| head -| keep);
+ return .{ .tag = tag, .head = head, .band = band, .over = head + band };
}
fn levelRows(n: u16) u16 {
@@ -494,14 +496,12 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
}
/// The display columns of the head's key cells: a spine hangs under each,
-/// through the tag's rows under them and the band's (UX D5).
+/// through the head's rows under them and the band's (UX D5).
fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void {
const h = (try TagState.head(p, arena, pane)) orelse return;
- const whole = try tagline.tagText(p, arena, pane);
- const shown = try tagline.wrapTag(p.settings.tab, arena, whole, tagline.tagWidth(p, id));
- const lead = whole.len - h.text.len;
+ const shown = try tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, id));
for (h.spans[0..h.cells]) |span| {
- const at = modal.positionAt(shown.text, shown.fromReal(lead + span.lo));
+ const at = modal.positionAt(shown.text, shown.fromReal(span.lo));
if (band.nspines == max_spines) return;
band.spines[band.nspines] = @intCast(File.rawDisplayCol(p.settings.tab, modal.lineSlice(shown.text, at.row), at.col));
band.nspines += 1;
@@ -680,7 +680,7 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![
return out.items;
}
-test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the band starts on the row under the head, in the rows the tag keeps from rest" {
+test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the band starts on the row under the head, which hangs under the tag's rows at rest (UX DESIGN M2)" {
const Key = pardes.Key;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 });
defer p.deinit();
@@ -702,23 +702,24 @@ test "a narrow band gives way and keeps its spines: the doc goes, the steps star
try std.testing.expectEqual(@as(u8, 1), band.nsteps);
try std.testing.expectEqual(band.spines[1] + 2, band.steps[0].x);
for (0..band.height) |y| try std.testing.expect(File.displayWidth(p.settings.tab, (try band.line(a, p.settings.tab, @intCast(y))).text) <= band.columns);
- // The band on the row under the head's one, in the row the tag keeps
- // from rest (UX E3): never a blank row between the head and its rows,
- // the body under whichever is lower.
+ // The head on the row under the tag's rows, the band on the row under
+ // it: never a blank row between them, the body under them.
const s = try p.render(a);
const r = p.view().rects[id];
const tag_y = p.tagTop(pane, r);
const at = covered(p, pane, id);
- try std.testing.expectEqual(@as(u16, 1), at.text);
+ try std.testing.expectEqual(@as(u16, 1), at.head);
+ try std.testing.expectEqual(rest, at.tag);
try std.testing.expectEqual(rest, pane.tag_rows);
- try std.testing.expectEqual((1 + band.height) -| rest, at.over);
- try std.testing.expectEqual(tag_y + 1, bandLayer(p, id).?.viewport.y);
- for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme());
- try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 0), "▶") != null);
+ try std.testing.expectEqual(1 + band.height, at.over);
+ try std.testing.expectEqual(tag_y + rest, bandLayer(p, id).?.viewport.y);
+ for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + rest + 1).grapheme());
+ try std.testing.expect(std.mem.startsWith(u8, try layerRow(a, bandLayer(p, id).?, 0), "Help ␣ l "));
+ try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 1), "▶") != null);
p.update(.{ .key = .{ .cp = Key.escape } });
}
-test "out of rest with no band, the rows a tag keeps from rest stay blank: a spine hangs only where a band row is" {
+test "out of rest with no band, the tag's rows are its rows at rest: no spine hangs in them (UX DESIGN M1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 });
defer p.deinit();
const pane = try p.setTestFile("one\n");
@@ -874,25 +875,27 @@ test "SPC Down unrolls the level into a band under the tag's text, drawn over th
_ = frame.reset(.retain_capacity);
const s = try p.render(frame.allocator());
const layer = bandLayer(p, id).?;
- try std.testing.expectEqual(p.tagTop(pane, r) + at.text, layer.viewport.y);
- try std.testing.expectEqual(at.band, layer.viewport.h);
+ try std.testing.expectEqual(p.tagTop(pane, r) + at.tag, layer.viewport.y);
+ try std.testing.expectEqual(at.over, layer.viewport.h);
// The body region starts where it did at rest: the band is over it.
const body = s.region(.body, id).?;
try std.testing.expectEqual(body_top, body.rect.y);
try std.testing.expect(layer.viewport.y + layer.viewport.h > body.rect.y);
- const first = try layerRow(frame.allocator(), layer, 0);
+ const first = try layerRow(frame.allocator(), layer, at.head);
try std.testing.expect(std.mem.indexOf(u8, first, "│") != null);
try std.testing.expect(std.mem.indexOf(u8, first, "▶ b buffer…") != null);
// The grid has the same rows, where the layer is, the body's under
// them drawn first: its last covered row is the band's.
var grid: std.ArrayList(u8) = .empty;
- for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme());
+ for (s.cells[@as(usize, layer.viewport.y + at.head) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme());
try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null);
const spine = (try of(p, frame.allocator(), pane, id)).?.spines[0];
try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + spine, layer.viewport.y + layer.viewport.h - 1).grapheme());
- // The head names the level and says how to roll it up.
- const head = try tagline.tagText(p, frame.allocator(), pane);
- try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ↑ roll up · ? field · esc"));
+ // The head, the layer's first row, names the level and says how to roll
+ // it up.
+ const head = (try TagState.head(p, frame.allocator(), pane)).?.text;
+ try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ? help"));
+ try std.testing.expect(std.mem.startsWith(u8, try layerRow(frame.allocator(), layer, 0), "␣ SPC "));
// Down moves the cursor; Up back to the first row, then rolls up.
p.update(.{ .key = .{ .cp = Key.down } });
try std.testing.expectEqual(@as(u8, 'c'), p.view().tag_state.hi);
@@ -931,7 +934,7 @@ test "a level's band covers what it needs: its pane keeps its rows where its hea
p.update(.{ .key = .{ .cp = Key.down } });
const pane = p.panes[low].?;
const at = covered(p, pane, low);
- const need = at.text + at.band;
+ const need = at.tag + at.over;
try std.testing.expect(at.band == takes(p, low) and need <= before[low].h);
try std.testing.expectEqualDeep(before, p.view().rects);
p.update(.{ .key = .{ .cp = Key.escape } });
@@ -1214,7 +1217,7 @@ test "a covered row belongs to the band: a click on a band row over the body mov
const band = (try of(p, frame.allocator(), pane, id)).?;
// The band's last row, over the body: its first step's row there.
const row: u16 = at.band - 1;
- const y = p.tagTop(pane, r) + at.text + row;
+ const y = p.tagTop(pane, r) + at.tag + at.head + row;
try std.testing.expect(y >= body_top);
const ln = try band.line(frame.allocator(), p.settings.tab, row);
const part = ln.parts[0];
@@ -1237,8 +1240,8 @@ test "a covered row belongs to the band: a click on a band row over the body mov
p.clock.now_ns = p.view().tag_state.due_ns;
p.sync();
const rolled = covered(p, pane, id);
- try std.testing.expect(rolled.band == 0 and rolled.text > pane.tag_rows);
- const hy = p.tagTop(pane, r) + rolled.text - 1;
+ try std.testing.expect(rolled.band == 0 and rolled.head > 1);
+ const hy = p.tagTop(pane, r) + rolled.tag + rolled.head - 1;
try std.testing.expect(hy >= body_top);
const hx = r.x + pardes.TAG_TEXT_INSET + 6;
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = hx, .row = hy } });
diff --git a/core/Command.zig b/core/Command.zig
index 132ad9e4..bb42bbbd 100644
--- a/core/Command.zig
+++ b/core/Command.zig
@@ -710,6 +710,12 @@ fn tagOf(p: *Pardes) ![]const u8 {
return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
}
+/// The head under the active pane's tag (UX DESIGN M2); none at rest.
+fn headOf(p: *Pardes) ![]const u8 {
+ const h = try TagState.head(p, p.scratch.allocator(), p.panes[p.view().active].?);
+ return if (h) |made| made.text else "";
+}
+
/// Whether `needle` is in `hay`, a run of two spaces or more in either read
/// as two: a right block's padding is its row's (UX D3).
fn has(hay: []const u8, needle: []const u8) bool {
@@ -753,7 +759,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqual(Prompt.Op.command, s.prompt.op);
try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus);
// The head: its key cell, the field, the count, the hints.
- try std.testing.expect(has(try tagOf(p), ": 18 commands Tab complete · ⏎ run · C-r history · esc"));
+ try std.testing.expect(has(try headOf(p), "18 commands C-r history"));
// The rows: the tag's words in its order, `in the tag`, the last ruled
// off; then the commands, each what it takes.
try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save "));
@@ -771,7 +777,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expect(has(first[9].text, "theme") and has(first[9].text, "<theme>"));
// Typing filters both, by the scorer, in their order.
typeKeys(p, "th");
- try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command "));
+ try std.testing.expect(has(try headOf(p), ": th = Exec th 1 command "));
try std.testing.expect(has(try bandRow(p, a, 0), "▶ theme "));
// Tab: the command, a space after it; the field's plain word is its
// pardes word once it is whole.
@@ -779,7 +785,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("theme ", s.field.text());
typeKeys(p, "acme");
const worn = colors.themes[p.theme_preview.?].name;
- try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn})));
+ try std.testing.expect(has(try headOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn})));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, s.kind);
try std.testing.expectEqualStrings(worn, p.theme().name);
@@ -789,7 +795,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
// `:sort`: the selections piped through sort, as `|sort` does.
while (p.nextEffect()) |_| {}
typeKeys(p, "%:sort");
- try std.testing.expect(has(try tagOf(p), ": sort = Exec Edit |sort 1 command"));
+ try std.testing.expect(has(try headOf(p), ": sort = Exec Edit |sort 1 command"));
p.update(.{ .key = .{ .cp = Key.enter } });
var asked: ?u32 = null;
while (p.nextEffect()) |effect| if (effect == .pipe) {
@@ -798,7 +804,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("sort", p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?.command);
// `:goto 2`: Look `:2`.
typeKeys(p, ":goto 2");
- try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try headOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
// S-Tab: the last row; Tab after it, round to the first. A tag word
@@ -846,7 +852,7 @@ test ":theme lists the themes and the whole window wears the current one, none d
typeKeys(p, ":theme ");
try std.testing.expectEqual(Rows.themes, s.prompt.command.rows);
try std.testing.expectEqual(@as(u16, @intCast(colors.themes.len)), s.nhits);
- try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, " {d} themes · the window wears the current one ", .{colors.themes.len})));
+ try std.testing.expect(has(try headOf(p), try std.fmt.allocPrint(a, " {d} themes · the window wears the current one ", .{colors.themes.len})));
// The window wears the first: its colours, its chrome; no pane dimmed.
try std.testing.expectEqualStrings(colors.themes[s.hits[0]].name, p.theme().name);
try std.testing.expectEqual(colors.Chrome.of(p.theme()), p.chrome().*);
@@ -890,9 +896,9 @@ test ":theme lists the themes and the whole window wears the current one, none d
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
try std.testing.expectEqual(@as(u16, 2), s.nhits);
try std.testing.expect(has(try bandRow(p, a, 0), "▶ on now"));
- try std.testing.expect(has(try tagOf(p), ": set Wrap = Exec Wrap 2 values "));
+ try std.testing.expect(has(try headOf(p), ": set Wrap = Exec Wrap 2 values "));
typeKeys(p, "of");
- try std.testing.expect(has(try tagOf(p), ": set Wrap of = Exec Wrap of 1 value "));
+ try std.testing.expect(has(try headOf(p), ": set Wrap of = Exec Wrap of 1 value "));
p.update(.{ .key = .{ .cp = Key.tab } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(!p.settings.wrap);
@@ -914,7 +920,7 @@ test ":theme lists the themes and the whole window wears the current one, none d
// :open: the line goes to Find, the rest of it the query, the keys
// after it typed into Find's field.
typeKeys(p, ":o");
- try std.testing.expect(has(try tagOf(p), ": o = Exec Find "));
+ try std.testing.expect(has(try headOf(p), ": o = Exec Find "));
typeKeys(p, " te");
try std.testing.expectEqual(TagState.Kind.pick, s.kind);
try std.testing.expectEqual(pardes.Pick.Source.find, pardes.Pick.live(p).?.source);
@@ -956,7 +962,7 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne
typeKeys(p, ":");
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("goto 2", s.field.text());
- try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try headOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("set Wrap off", s.field.text());
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
@@ -1087,3 +1093,35 @@ test ": lists the words of the pane's kind its tag does not show now, `for this
try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
try std.testing.expectEqualStrings("one\n", pane.file.?.content);
}
+
+test ": hangs its field under the tag, which stays as at rest; `:` on the empty field gives the keyboard to that tag's own text right above it, the head's row the body's again (UX DESIGN M3)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const pane = try p.setTestFile("one\ntwo\n");
+ pane.tag.own = try p.gpa.dupe(u8, "notes");
+ p.sync();
+ const id = p.view().active;
+ const r = p.view().rects[id];
+ const head_y = p.tagTop(pane, r) + pane.tag_rows;
+ const rest = try a.dupe(u8, try tagOf(p));
+ const at_rest = try a.dupe(pardes.Cell, (try p.render(a)).cells);
+ const cols = p.surface.cols;
+ typeKeys(p, ":");
+ try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
+ try std.testing.expectEqualStrings(rest, try tagOf(p));
+ var s = try p.render(a);
+ try std.testing.expectEqualStrings(":", s.at(r.x + pardes.TAG_TEXT_INSET, head_y).grapheme());
+ typeKeys(p, ":");
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqual(panes.Pane.Focus.tag, pane.focus);
+ try std.testing.expectEqualStrings(rest, try tagOf(p));
+ s = try p.render(a);
+ for (r.x..r.x + r.w) |x| try std.testing.expectEqualStrings(at_rest[@as(usize, head_y) * cols + x].grapheme(), s.cells[@as(usize, head_y) * cols + x].grapheme());
+ // The caret at the start of the tag's own text.
+ const own: u16 = @intCast(panes.File.displayWidth(p.settings.tab, rest[0..std.mem.indexOf(u8, rest, "notes").?]));
+ try std.testing.expectEqual(r.x + pardes.TAG_TEXT_INSET + own, s.cursor.?.x);
+ try std.testing.expectEqual(p.tagTop(pane, r), s.cursor.?.y);
+}
diff --git a/core/Core.zig b/core/Core.zig
index cf53bb4d..0b602ba2 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -2045,8 +2045,8 @@ pub fn layOut(p: *Pardes) void {
const wa = wrap_fba.allocator();
const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null;
// The tag's cursor and selections are offsets in its text at rest:
- // a head shown over its own text moves none of them (UX D1).
- const at_rest = if (pardes.Trail.outOfRest(p, pane) or pardes.TagState.asks(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix;
+ // a question shown over its own text moves none of them (UX D13).
+ const at_rest = if (pardes.TagState.asks(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix;
const lead = if (at_rest) |made| made.len else pane.tag_lead;
if (lead != pane.tag_lead) {
const t = &pane.tag;
@@ -2076,12 +2076,11 @@ pub fn layOut(p: *Pardes) void {
caret_row = std.mem.count(u8, shown.text[0..@min(shown.fromReal(cur), shown.text.len)], "\n");
}
if (!pane.tag_expanded) wanted = 1;
- // Out of rest the tag keeps exactly the rows its own text takes at
- // rest: its head's rows past them and the band under it are drawn
- // over the top rows of its body, which never move for them (UX
- // DESIGN I1, Band.covered); its head is drawn whole from its first
- // row. A picker's preview starts under them, as a file's first
- // lines could not be put under a band otherwise (Pick.previewing).
+ // Out of rest the tag keeps exactly its rows at rest: its head and
+ // band hang under it, drawn over the top rows of its body, which
+ // never move for them (UX DESIGN I1, M2, Band.covered). A picker's
+ // preview starts under them, as a file's first lines could not be
+ // put under a band otherwise (Pick.previewing).
const host = pardes.TagState.hostOf(p) == id and !pane.collapsed;
if (host) wanted = layout.wantedTagRows(p, id);
pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
diff --git a/core/Messages.zig b/core/Messages.zig
index 1e03f4e0..35eb7f51 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -1593,13 +1593,14 @@ test "a file changed on disk under unsaved text asks in its tag and never takes
const prefix = try pardes.tagline.tagPrefix(p, pane);
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's level shown) the level's head, not the question;
- // at rest again, the question.
+ try std.testing.expect(pardes.TagState.asks(p, pane));
+ // Out of rest (SPC's level shown) the tag as at rest, the question in
+ // it, the level's head under it (UX DESIGN M1); at rest, the question.
p.update(.{ .key = .{ .cp = ' ' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
- try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") == null);
+ try std.testing.expectEqualStrings(shown, try pardes.tagline.tagText(p, frame.allocator(), pane));
+ try std.testing.expect(std.mem.startsWith(u8, (try pardes.TagState.head(p, frame.allocator(), pane)).?.text, "␣ ▸ "));
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);
diff --git a/core/Pick.zig b/core/Pick.zig
index c39e8ec9..6899f607 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -1,11 +1,12 @@
//! A picker (pick-ui SPEC.md §5, direction E): a list of places, panes or
-//! names unrolled in the tag of the pane its Enter lands in (§3.5): the
-//! asking pane when it reads, else its reader, made for the picker when it
-//! has none and taken away again by Esc. Its query is typed in that tag's
-//! field (TagState.field), its rows hang in the band under it (Band.zig)
-//! eleven at a time around the cursor, and that pane's body is the preview:
-//! the current row's file at its line, its own text set aside meanwhile and
-//! put back when the picker rolls up.
+//! names hung under the tag of the pane that asked, which keeps the
+//! keyboard (UX DESIGN O1). Its query is typed in the head's field
+//! (TagState.field), its rows hang in the band under it (Band.zig) eleven
+//! at a time around the cursor, and the body of the pane its Enter lands in
+//! is the preview: the current row's file at its line, its own text set
+//! aside meanwhile and put back when the picker rolls up. That pane is the
+//! asking one when it reads or is untouched, else its reader, else free
+//! space, else one made under it for the picker and taken away by Esc.
//!
//! The rows are Query.zig's producers', re-presented: names scored by
//! Names.zig a frame's count at a time (Find's listing from the disk
@@ -93,17 +94,22 @@ word: Kind.Buf(24) = .{},
keys: Kind.Buf(4) = .{},
/// Where Find and Grep look; what the rows' paths are relative to.
dir: Kind.Buf(4096) = .{},
-/// The pane that asked, and the one its Enter lands in, by serial.
+/// The pane that asked, under whose tag it hangs, and the one its Enter
+/// lands in, whose body previews, by serial.
owner: u32 = 0,
landing: u32 = 0,
/// The landing pane was made for it: Esc takes it away.
made: bool = false,
-/// Its band's rows at most: 40 % of its host pane's rows at open (UX D6),
+/// Its band's rows at most: 40 % of its asking pane's rows at open (UX D6),
/// fixed: the layout that borrows the host's body from its column reads
/// it, and a pane laid out again changes it no more than typing does.
cap: u16 = 0,
/// Unrolled in a view's tag now.
unrolled: bool = false,
+/// The most rows its list has had since it unrolled, eleven at most: its
+/// band grows with a list whose rows come later and never shrinks while it
+/// is up (bandRows, UX D6).
+tall: u8 = 0,
names: Names = .{},
/// A Grep's lines, as the disk engine sends them (Query.take).
found: std.ArrayList(Query.Found) = .empty,
@@ -209,16 +215,39 @@ pub fn live(p: *const Pardes) ?*Pick {
/// band (Pardes.sync), as a file's first lines could not be put under it
/// otherwise (UX DESIGN I1's "a picker's landing line at a third below
/// the band" for Find's line 1: W1's reading); before that, and at rest
-/// again, the pane's own text stays where it was under the band.
+/// again, the pane's own text stays where it was under the band. Code
+/// actions' body is their preview from the first, their edit's ghost lines
+/// in it (UX DESIGN I1: "a picker and code actions (whose body is the
+/// preview) keep D6"): under the head and the band, never under them.
pub fn previewing(p: *const Pardes, id: usize) bool {
const pk = live(p) orelse return false;
const pane = p.panes[id] orelse return false;
- return pk.previewed and pane.serial == pk.landing;
+ return (pk.previewed or pk.source == .actions) and pane.serial == pk.landing;
}
-/// A picker of `source` asked from pane `from`, unrolled in the tag of the
-/// pane its Enter will land in (SPEC §3.5), its field `query`. `rows` are
-/// a list's (`source` `list`, titled `word`).
+/// Whether pane `id` shows the live picker's preview, being its landing
+/// pane, for the layout: a body of 60 % kept under what is above it (UX
+/// D6, DESIGN O1), the head and the band among that when it asked too.
+/// Panes and Themes preview in no pane.
+pub fn previewPane(p: *const Pardes, id: usize) bool {
+ const pk = live(p) orelse return false;
+ const pane = p.panes[id] orelse return false;
+ return pane.serial == pk.landing and pk.source != .panes and pk.source != .themes;
+}
+
+/// The live picker whose rows pane `pane`'s body previews, it being its
+/// landing pane: what its tag names in place of the preview
+/// (tagline.named, UX DESIGN M3); none for a themes or actions picker,
+/// whose landing is the asking pane's own text.
+pub fn landingOf(p: *const Pardes, pane: *const Pane) ?*const Pick {
+ const pk = live(p) orelse return null;
+ if (pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null;
+ return pk;
+}
+
+/// A picker of `source` asked from pane `from`, hung under its tag (UX
+/// DESIGN O1), its field `query`. `rows` are a list's (`source` `list`,
+/// titled `word`).
pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void {
const asker = p.panes[from] orelse return;
TagState.toRest(p);
@@ -229,8 +258,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
// Find and Grep from the work tree's root (W8), as other finders search.
pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker));
pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err);
+ pk.cap = p.view().rects[from].h * 2 / 5;
hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err);
- if (p.paneBySerial(pk.landing)) |host| pk.cap = p.view().rects[host].h * 2 / 5;
unroll(p, pk, query);
start(p, pk);
filter(p, pk);
@@ -341,30 +370,28 @@ fn nkept(p: *const Pardes) usize {
return n;
}
-/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when
-/// it reads; its reader when it is held and has one; else an untouched
-/// pane, `from` itself first (UX J1), which previews as a reading pane does
-/// and is given back as it was on Esc; else a pane made where its reader
-/// would go, empty until the preview fills it. The keyboard stays where it
-/// was: the landing pane is the tag's host.
+/// Picker `pk` asked from pane `from`, which keeps the keyboard and hangs
+/// its head and band under its tag (UX DESIGN O1). The pane it lands in,
+/// whose body previews: `from` when it reads; its reader when it is held
+/// and has one; else an untouched pane, `from` itself first (UX J1), which
+/// previews as a reading pane does and is given back as it was on Esc;
+/// else a pane made where its reader would go, empty until the preview
+/// fills it. A source with nothing to preview makes no pane and sets
+/// nothing aside: Panes (a row is a pane on the screen), Themes (the whole
+/// window wears the row) and code actions (their edit in the asking text).
fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
+ defer p.view().active = from;
const asker = p.panes[from].?;
pk.owner = asker.serial;
+ pk.landing = asker.serial;
pk.made = false;
- // A theme is no place: its list is the asking pane's own tag (§3.5),
- // and its preview the whole window; an action's is that text's edit.
- if (pk.source == .themes or pk.source == .actions) {
- pk.landing = asker.serial;
- p.view().active = from;
- return;
- }
+ if (pk.source == .panes or pk.source == .themes or pk.source == .actions) return;
var reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker);
if (reader == null) if (layout.freeSpace(p, from, .reader)) |free| if (free == .pane) {
reader = free.pane;
};
pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial;
pk.made = reader == null;
- p.view().active = from;
}
/// A pane made for a picker where pane `from`'s reader goes: under it, or
@@ -380,17 +407,18 @@ fn landingFor(p: *Pardes, from: usize) !usize {
return free;
}
-/// Picker `pk` live in the live view's tag: its host its landing pane, its
-/// field `query`, the cursor where it was.
+/// Picker `pk` live in the live view's tag: hung under its asking pane's
+/// tag (UX DESIGN O1), its field `query`, the cursor where it was.
fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void {
const v = p.view();
const s = &v.tag_state;
s.kind = .pick;
s.pick = pk.id;
- s.host = pk.landing;
+ s.host = pk.owner;
s.field.set(query);
s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) };
pk.unrolled = true;
+ pk.tall = 0;
pk.shown = no_row;
pk.previewed = false;
// The whole window previews a theme.
@@ -572,6 +600,7 @@ fn toBest(p: *Pardes, pk: *Pick) void {
/// current row.
pub fn produceAll(p: *Pardes, tick: bool) void {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
+ pk.tall = @intCast(@max(pk.tall, @min(have(p, pk), Band.Cursor.shown)));
if (pk.names.busy()) {
// A cursor on the best match follows it while the rest are
// scored.
@@ -585,6 +614,12 @@ pub fn produceAll(p: *Pardes, tick: bool) void {
};
}
+/// The rows a picker's source has: every name it scores (not what the
+/// query keeps), a Grep's lines and All's places for this query.
+fn have(p: *const Pardes, pk: *const Pick) usize {
+ return if (fuzzy(pk)) pk.names.cands.items.len else count(p, pk);
+}
+
/// The frames a live picker still owes: scoring, a preview (nextWake's).
pub fn busy(p: *const Pardes) bool {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
@@ -790,9 +825,11 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me
// ---- the tag ----
-/// The head of the landing pane's tag (SPEC §5.3): the key cells, the
-/// source's word, the query, the count `cursor/total` and `•marked`; on a
-/// second row the other sources' words, under spines from the key cells.
+/// The head under the asking pane's tag (SPEC §5.3, UX DESIGN M2, O1): the
+/// key cells, the source's word, the query, the count `cursor/total` and
+/// `•marked`, and one hint, `M-l acts`, the key to the acts (UX DESIGN O4:
+/// no row of acts and sources; each source has its own key, M-h switches
+/// keeping the query).
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const pk = live(p) orelse return null;
const s = &p.view().tag_state;
@@ -815,65 +852,29 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n });
if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len});
if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯");
- // Themes, actions and Lists have no acts and no other sources: no
- // second row.
- if (pk.source == .themes or pk.source == .actions or pk.source == .lists) {
- const hints = text.items.len;
- try b.styled(switch (pk.source) {
- .themes => "⏎ wear it · esc",
- .lists => "⏎ reopen it · esc",
- else => "⏎ or 1-9 apply it · esc",
- }, .dim);
- try b.right(counted, hints);
- var h = b.done();
- h.caret = caret;
- return h;
- }
- try b.right(counted, text.items.len);
- // The second row, one row (UX D2): under the spines from the key
- // cells, from two cells right of the last, the acts, `|`, the other
- // sources' words, each switching to it, the `|` and the sources dim
- // (UX D4); what does not fit is dropped from the right (the sources
- // first) and the row ends in a dim `…` (M-l and M-h reach them all).
- try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0);
- var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined;
- var nw: usize = 0;
- for (acts) |act| if (offered(pk, act)) {
- offer[nw] = act.word;
- nw += 1;
- };
- const nacts = nw;
- offer[nw] = "|";
- nw += 1;
- inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != .lists and src != pk.source) {
- offer[nw] = words.get(src).word;
- nw += 1;
- };
- for (offer[0..nw], 0..) |word, i| {
- const gap: usize = @intFromBool(i > 0);
- const rest: usize = if (i + 1 < nw) 2 else 0;
- if (b.col() + gap + File.displayWidth(p.settings.tab, word) + rest > b.width) {
- try b.put(if (gap > 0) " " else "");
- try b.styled("…", .dim);
- break;
- }
- try b.put(if (gap > 0) " " else "");
- if (i >= nacts) try b.styled(word, .dim) else try b.put(word);
- }
+ // Themes, code actions and Lists have no acts: no hint.
+ const hints = text.items.len;
+ if (pk.source != .themes and pk.source != .actions and pk.source != .lists) try b.styled("M-l acts", .dim);
+ try b.right(counted, hints);
var h = b.done();
h.caret = caret;
return h;
}
-/// The band's rows (UX D6): as many as the list will show, from what the
-/// source has (not what the query keeps: typing never moves the body),
-/// four at least, eleven at most, and its `cap` at most (the host pane's
-/// 40 % at open: the layout asks this while it lays the column out, when
-/// no pane has its rows yet).
+/// The band's rows (UX D6, DESIGN O4): as many as the list will show, from
+/// what the source has (not what the query keeps: typing never moves the
+/// body) and the most it has had (`tall`): a list known at open exactly its
+/// rows, one whose rows come later (Find, Grep, All, Symbols) three at
+/// least, growing as they come; eleven at most, and its `cap` at most (the
+/// asking pane's 40 % at open: the layout asks this while it lays the
+/// column out, when no pane has its rows yet).
pub fn bandRows(p: *const Pardes) u16 {
const pk = live(p) orelse return 0;
- const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len;
- const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), pk.cap));
+ const later: usize = switch (pk.source) {
+ .find, .grep, .all, .symbols => 3,
+ else => 1,
+ };
+ const rows: usize = @max(1, @min(Band.Cursor.shown, @max(later, pk.tall, have(p, pk)), pk.cap));
// Its second step's rows too: the sources, the acts and what they act on.
return @intCast(switch (pk.spine) {
.sources => @max(rows, spine_rows.len),
@@ -982,7 +983,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi
/// previewing.
pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize {
const pk = live(p) orelse return null;
- if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists) return null;
+ if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists or pk.source == .panes) return null;
if (pk.landing == pk.owner) {
w.writeAll("⏎ lands here") catch return null;
} else {
@@ -1512,9 +1513,18 @@ fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void {
for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa);
pk.nrefined = 0;
pk.marks.clearRetainingCapacity();
+ const from_panes = pk.source == .panes;
pk.source = to;
pk.word.set(words.get(to).word);
pk.keys.set(words.get(to).keys);
+ // From Panes, which previews in no pane (hostIn), to a source that
+ // does: its preview where it would have been had it opened as this one.
+ if (from_panes and to != .panes) {
+ var query: Kind.Buf(256) = .{};
+ query.set(s.field.text());
+ hostIn(p, pk, p.paneBySerial(pk.owner) orelse p.view().active) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ unroll(p, pk, query.slice());
+ }
start(p, pk);
filter(p, pk);
}
@@ -1843,16 +1853,19 @@ pub fn walkList(p: *Pardes, id: usize, forward: bool) bool {
}
/// Look on a list word in pane `id`'s trail (SPEC §6.3), or a walk onto
-/// it at step `walking` (UX L'1): the list unrolled again in that pane's
-/// tag, its rows, marks, cursor and query as they were.
+/// it at step `walking` (UX L'1): the list unrolled again under that
+/// reading pane's tag, which asks it now and previews it, its rows, marks,
+/// cursor and query as they were.
pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void {
const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
const pane = p.panes[id] orelse return;
TagState.toRest(p);
p.resume_at = 0;
touch(p, pk);
+ pk.owner = pane.serial;
pk.landing = pane.serial;
pk.made = false;
+ p.view().active = id;
unroll(p, pk, pk.query.slice());
unrollRows(p, pk);
pk.walking = walking;
@@ -1906,13 +1919,69 @@ pub fn keyAtRest(p: *Pardes, k: Key) void {
p.resume_at = 0;
}
-/// B3 on a picker's row (mouse.zig bandPress): Enter on it.
+/// Enter on the live picker's current row: B3 on its text where it
+/// previews (mouse.zig, UX DESIGN O3).
pub fn landHere(p: *Pardes) void {
const pk = live(p) orelse return;
if (pk.source == .lists) return reopenListed(p, pk);
if (pk.spine == .rows) land(p, .walk);
}
+/// A press on row `row` of the live picker's band (mouse.zig bandPress, UX
+/// DESIGN O2): B1 (`enter` false) puts the cursor on it, the list's or the
+/// act step's; B3 does what Enter does there (`below`: Shift-B3, as
+/// S-Enter): the row landed, the act applied, the source switched to, the
+/// theme worn, the action applied. A row of the act step or the source
+/// spine is its key's, its first byte (actStep, steps).
+pub fn press(p: *Pardes, row: Band.Row, enter: bool, below: bool) void {
+ const pk = live(p) orelse return;
+ const s = &p.view().tag_state;
+ if ((pk.spine == .acts or pk.spine == .sources) and row.key > 0) {
+ if (enter) return key(p, .{ .cp = row.text[0] });
+ if (pk.spine == .acts) pk.act_at = @intCast(row.index);
+ return;
+ }
+ if (pk.spine != .rows or row.index >= count(p, pk)) return;
+ s.rows.at = row.index;
+ if (!enter) return;
+ if (pk.source == .lists) return reopenListed(p, pk);
+ if (pk.source == .themes or pk.source == .actions) return key(p, .{ .cp = Key.enter });
+ land(p, if (below) .below else .walk);
+}
+
+/// The wheel over the live picker's head or band (UX DESIGN O2): its
+/// cursor `delta` rows on, the band's eleven following it and the preview
+/// with them, as the keys move it.
+pub fn wheel(p: *Pardes, delta: i32) void {
+ const pk = live(p) orelse return;
+ const s = &p.view().tag_state;
+ const n = @min(count(p, pk), std.math.maxInt(u16));
+ if (n == 0 or pk.spine != .rows) return;
+ s.rows.at = @intCast(std.math.clamp(@as(i64, s.rows.at) + delta, 0, @as(i64, @intCast(n)) - 1));
+ if (fuzzy(pk)) pk.names.reachTo(@as(usize, s.rows.at) + Band.Cursor.shown);
+}
+
+/// Whether screen row `row` of pane `id` is text the live picker previews:
+/// its landing pane's body, a place shown in it (UX DESIGN O3). B2 and B3
+/// there land it first: acting on the file is taking it.
+pub fn previewsAt(p: *const Pardes, id: usize, row: u16) bool {
+ const pk = live(p) orelse return false;
+ const pane = p.panes[id] orelse return false;
+ if (pane.serial != pk.landing or !pk.previewed or pk.source == .themes or pk.source == .actions) return false;
+ return row >= p.bodyTop(pane, p.view().rects[id]);
+}
+
+/// The live picker, waiting or not, ended as Esc ends it when what is about
+/// to run changes or closes pane `id`, the pane it asks from or previews in
+/// (UX DESIGN O3: Del, Get, Undo, Put, Keep, a walk step there, a Look that
+/// lands there, the pane closed): the preview's own text back, a pane made
+/// for it gone with it. Anything else leaves it up.
+pub fn yieldFor(p: *Pardes, id: usize) void {
+ const pk = live(p) orelse return;
+ const pane = p.panes[id] orelse return;
+ if (pane.serial == pk.owner or pane.serial == pk.landing) TagState.toRest(p);
+}
+
/// Enter in Lists (UX L'3): the kept picker under its cursor unrolled again
/// as it was left, where Lists was asked from, and the newest now.
fn reopenListed(p: *Pardes, pk: *Pick) void {
@@ -2155,6 +2224,12 @@ fn tagOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 {
return pardes.tagline.tagText(p, arena, p.panes[id].?);
}
+/// The head under pane `id`'s tag (UX DESIGN M2); none at rest.
+fn headOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 {
+ const h = try TagState.head(p, arena, p.panes[id].?);
+ return if (h) |made| made.text else "";
+}
+
fn paneCount(p: *const Pardes) usize {
var n: usize = 0;
for (p.panes) |slot| n += @intFromBool(slot != null);
@@ -2169,7 +2244,7 @@ fn settle(p: *Pardes) void {
}
}
-test "a picker from a held pane unrolls in a reader made for it: its rows in the band, the body the current row's file, Esc takes the reader away" {
+test "a picker from a held pane hangs under that pane's tag, which keeps the keyboard; its preview in a reader made for it under it, whose tag is `‹@pN ›`: the body the current row's file, Esc takes the reader away (UX DESIGN O1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2191,12 +2266,13 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
const npanes = paneCount(p);
open(p, asker, .find, "", "", "");
const pk = live(p).?;
- // A reader made for it, under the asker; its tag is the picker's.
+ // A reader made for it, under the asker, which hangs the picker.
try std.testing.expectEqual(npanes + 1, paneCount(p));
try std.testing.expect(pk.made);
const reader = p.paneBySerial(pk.landing).?;
- try std.testing.expectEqual(@as(?usize, reader), TagState.hostOf(p));
+ try std.testing.expectEqual(@as(?usize, asker), TagState.hostOf(p));
try std.testing.expectEqual(asker, p.view().active);
+ try std.testing.expect(p.view().rects[reader].y > p.view().rects[asker].y);
settle(p);
try std.testing.expectEqual(@as(usize, 2), count(p, pk));
for ("pick") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
@@ -2205,19 +2281,20 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
- const tag = try tagOf(p, a, reader);
- // Out of rest no path (UX D1): not the previewed file's, not Keep;
- // the head starts the tag's text.
- const first = tag[0..std.mem.indexOfScalar(u8, tag, '\n').?];
- try std.testing.expect(std.mem.startsWith(u8, first, "␣ f Find pick ") and std.mem.endsWith(u8, first, " 1/1"));
- try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null);
+ // Its tag the owner's word alone (UX DESIGN M3, O1); the head under
+ // the asker's.
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, a, reader), "‹@p"));
+ try std.testing.expectEqualStrings("", try headOf(p, a, reader));
+ const tag = try headOf(p, a, asker);
+ try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick ") and std.mem.indexOf(u8, tag, " 1/1") != null);
// The body previews the row's file, after a frame of its own.
p.update(.tick);
try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
_ = try p.render(a);
- const r = p.view().rects[reader];
+ const r = p.view().rects[asker];
try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme());
- try std.testing.expect(Band.covered(p, p.panes[reader].?, reader).band >= 1);
+ try std.testing.expect(Band.covered(p, p.panes[asker].?, asker).band >= 1);
+ try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over);
// Esc: the reader made for it goes, the asker as it was.
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqual(npanes, paneCount(p));
@@ -2226,7 +2303,7 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
try std.testing.expectEqualStrings("pick", pk.query.slice());
}
-test "a picker's act row is one row under the spines, two cells right of the last: what does not fit dropped from the right, the sources first, a dim `…` ending it" {
+test "a picker's head is one row: the count and one dim hint at its right end, `M-l acts`; no row of acts and sources, the list's rows right under it; Themes hints nothing (UX DESIGN O4)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 40 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2237,25 +2314,31 @@ test "a picker's act row is one row under the spines, two cells right of the las
_ = try p.setTestFile("held\n");
const asker = p.view().active;
Trail.keep(p.panes[asker].?);
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
p.stream.engine = .walk;
open(p, asker, .find, "", "", "");
- const reader = p.paneBySerial(live(p).?.landing).?;
+ settle(p);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
- const tag = try tagOf(p, a, reader);
- var rows = std.mem.splitScalar(u8, tag, '\n');
- try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find "));
- const acts_row = rows.next().?;
- try std.testing.expect(rows.next() == null);
- try std.testing.expect(std.mem.startsWith(u8, acts_row, "│ │ Walk Look "));
- try std.testing.expect(std.mem.endsWith(u8, acts_row, " …"));
- try std.testing.expect(File.displayWidth(p.settings.tab, acts_row) <= pardes.tagline.tagWidth(p, reader));
- const h = (try head(p, a, p.panes[reader].?)).?;
+ const tag = try headOf(p, a, asker);
+ try std.testing.expect(std.mem.indexOfScalar(u8, tag, '\n') == null);
+ try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find ") and std.mem.endsWith(u8, tag, "1/1 M-l acts"));
+ try std.testing.expectEqual(@as(usize, pardes.tagline.tagWidth(p, asker)), File.displayWidth(p.settings.tab, tag));
+ const h = (try head(p, a, p.panes[asker].?)).?;
try std.testing.expect(h.spans[h.spans.len - 1].style == .dim);
+ // The band's first row the list's first.
+ const band = (try Band.of(p, a, p.panes[asker].?, asker)).?;
+ try std.testing.expect(std.mem.indexOf(u8, (try band.line(a, p.settings.tab, 0)).text, "▶ alpha.zig") != null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ open(p, asker, .themes, "", "", "");
+ const themes = try headOf(p, a, asker);
+ try std.testing.expect(std.mem.indexOf(u8, themes, "esc") == null and std.mem.indexOf(u8, themes, "M-l") == null and std.mem.indexOf(u8, themes, "⏎") == null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
}
-test "a picker's band is sized from its list at open, 4 rows at least, and typing never moves it" {
+test "a picker's band is its list's rows (UX DESIGN O4, D6): a list whose rows come later (Find) holds 3 at open, never moved by typing; a list known at open exactly its rows: SPC b b with two panes covers its head and 2 rows" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2272,19 +2355,29 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin
p.stream.engine = .walk;
open(p, asker, .find, "", "", "");
settle(p);
- const reader = p.paneBySerial(live(p).?.landing).?;
+ const reader = asker;
p.sync();
const rows = Band.covered(p, p.panes[reader].?, reader).band;
- // One or two files listed: four rows, ground under them.
- try std.testing.expectEqual(@as(u16, 4), rows);
+ // One file listed: three rows, ground under it.
+ try std.testing.expectEqual(@as(u16, 3), rows);
for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
settle(p);
p.sync();
try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
try std.testing.expectEqual(rows, Band.covered(p, p.panes[reader].?, reader).band);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Two panes: SPC b b's band two rows.
+ p.newScratchBelow(asker);
+ p.view().active = asker;
+ p.sync();
+ for (" bb") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ p.sync();
+ try std.testing.expectEqual(Source.panes, live(p).?.source);
+ const at = Band.covered(p, p.panes[asker].?, asker);
+ try std.testing.expect(at.head == 1 and at.band == 2);
}
-test "a picker's band is capped once at open at 40 % of its host pane's rows; the host borrows from its column for a body of 60 % before the band gives way: a Grep from a held pane at 100x30 previews 8 rows at least" {
+test "a picker's band is capped once at open at 40 % of its asking pane's rows; the pane it previews in borrows from its column for a body of 60 %: a Grep from a held pane at 100x30 previews 8 rows at least, in a reader made under it (UX D6, DESIGN O1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2302,20 +2395,24 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th
p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
p.stream.engine = .walk;
p.sync();
+ const at_open = p.view().rects[asker].h;
open(p, asker, .grep, "", "", "");
const reader = p.paneBySerial(live(p).?.landing).?;
- const at_open = p.view().rects[reader].h;
+ try std.testing.expect(reader != asker);
for ("pub fn") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ // Its lines after the typing's pause: the band from 3 rows to its cap.
+ if (p.stream.due_ns) |due| p.clock.now_ns = due;
settle(p);
+ try std.testing.expectEqual(@as(usize, 40), count(p, live(p).?));
p.update(.{ .key = .{ .cp = Key.down } });
+ p.update(.tick);
p.sync();
- const pane = p.panes[reader].?;
- const r = p.view().rects[reader];
- const at = Band.covered(p, pane, reader);
+ const at = Band.covered(p, p.panes[asker].?, asker);
try std.testing.expectEqual(@min(Band.Cursor.shown, at_open * 2 / 5), at.band);
- // The rows under the band, the preview's (no row previewed yet: the
- // band over the reader's text, UX DESIGN I1).
- const under = r.h - @max(pane.tag_rows, at.text + at.band);
+ // The preview's rows under the reader's tag, no band over them.
+ const r = p.view().rects[reader];
+ try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over);
+ const under = r.h - p.panes[reader].?.tag_rows;
try std.testing.expect(under >= 8);
try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3);
}
@@ -2345,8 +2442,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
try std.testing.expectEqual(@as(u16, 2), s.rows.at);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
- const refs = try tagOf(p, frame.allocator(), id);
- try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null);
+ const refs = try headOf(p, frame.allocator(), id);
+ try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.endsWith(u8, refs, " 3/4 •1 M-l acts"));
p.update(.{ .key = .{ .cp = 'a', .alt = true } });
try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len);
p.update(.{ .key = .{ .cp = 'a', .alt = true } });
@@ -2364,8 +2461,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
settle(p);
try std.testing.expectEqual(@as(usize, 1), count(p, pk));
_ = frame.reset(.retain_capacity);
- const refined = try tagOf(p, frame.allocator(), id);
- try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null);
+ const refined = try headOf(p, frame.allocator(), id);
+ try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.endsWith(u8, refined, " 1/1 M-l acts"));
// Backspace twice: the `w` goes, then the refinement, its query back.
p.update(.{ .key = .{ .cp = Key.backspace } });
p.update(.{ .key = .{ .cp = Key.backspace } });
@@ -3178,8 +3275,8 @@ test "a picker's preview starts under its band: its landing line ⌈visible/3⌉
try std.testing.expect(previewing(p, id));
try std.testing.expectEqualStrings(path, pane.file.?.path);
const at = Band.covered(p, pane, id);
- try std.testing.expectEqual(@as(u16, 0), at.over);
- try std.testing.expectEqual(p.tagTop(pane, r) + at.text + at.band, p.bodyTop(pane, r));
+ try std.testing.expectEqual(@as(u16, 0), pane.view.covered);
+ try std.testing.expectEqual(p.tagTop(pane, r) + at.tag + at.over, p.bodyTop(pane, r));
try std.testing.expectEqual(@as(usize, 59 - (pane.rows + 2) / 3), pane.file.?.scroll);
// Line 1: on the row right under the band.
p.update(.{ .key = .{ .cp = Key.down } });
@@ -3698,3 +3795,156 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l
try std.testing.expectEqualStrings("/", live(p).?.dir.slice());
p.update(.{ .key = .{ .cp = Key.escape } });
}
+
+test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, its body under it; the head hangs under the asking pane's tag (UX DESIGN M3, O1)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ const npanes = paneCount(p);
+ open(p, asker, .find, "", "", "");
+ const pk = live(p).?;
+ try std.testing.expect(pk.made);
+ const reader = p.paneBySerial(pk.landing).?;
+ settle(p);
+ p.update(.tick);
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const owner = try std.fmt.allocPrint(a, "‹@p{d} › ", .{p.panes[asker].?.serial});
+ try std.testing.expectEqualStrings(owner, try tagOf(p, a, reader));
+ const s = try p.render(a);
+ const r = p.view().rects[reader];
+ var row: std.ArrayList(u8) = .empty;
+ const ra = p.view().rects[asker];
+ for ([_]struct { y: u16, starts: []const u8 }{
+ // The tag's row, the owner's word; the body's under it.
+ .{ .y = r.y, .starts = std.mem.trimEnd(u8, owner, " ") },
+ .{ .y = r.y + 1, .starts = "1▸const alpha" },
+ // The head under the asker's tag.
+ .{ .y = ra.y + p.panes[asker].?.tag_rows, .starts = "␣ f Find " },
+ }) |want| {
+ row.clearRetainingCapacity();
+ for (s.cells[@as(usize, want.y) * s.cols + r.x + pardes.TAG_TEXT_INSET ..][0 .. r.w - pardes.TAG_TEXT_INSET]) |cell| try row.appendSlice(a, cell.grapheme());
+ try std.testing.expect(std.mem.startsWith(u8, std.mem.trimStart(u8, row.items, " "), want.starts));
+ }
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+}
+
+test "SPC b b from a held pane hangs under that pane's own tag (UX DESIGN O1): no pane made, nothing set aside, the keyboard in its field; a Panes list never names a picker's preview" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ exec.runBuiltin(p, .New, held, "New", null);
+ p.view().active = held;
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const rest = try a.dupe(u8, try tagOf(p, a, held));
+ const npanes = paneCount(p);
+ for (" bb") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ const pk = live(p).?;
+ try std.testing.expectEqual(Source.panes, pk.source);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expect(!pk.made);
+ try std.testing.expectEqual(p.panes[held].?.serial, pk.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ try std.testing.expectEqual(held, p.view().active);
+ try std.testing.expectEqualStrings(rest, try tagOf(p, a, held));
+ try std.testing.expect(std.mem.startsWith(u8, try headOf(p, a, held), "␣ b Panes "));
+ settle(p);
+ p.update(.tick);
+ // Nothing previewed, nothing said of a preview: the held pane's own text.
+ try std.testing.expect(pk.aside == null and p.panes[held].?.file.?.output == null);
+ var said: [256]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&said);
+ try std.testing.expect(sentence(p, &w) == null);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ // A list from the held pane previews in the untouched +New (UX J1);
+ // switched to Panes, the +New previewing is not among its rows.
+ const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path});
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ const scratch = p.paneBySerial(live(p).?.landing).?;
+ try std.testing.expect(scratch != held);
+ try std.testing.expectEqualStrings(b_path, p.panes[scratch].?.file.?.path);
+ p.update(.{ .key = .{ .cp = 'h', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'b', .text = "b" } });
+ try std.testing.expectEqual(Source.panes, live(p).?.source);
+ try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(Trail.untouched(p, p.panes[scratch].?));
+}
+
+test "a picker from a held pane with a reader hangs under the held pane's tag and previews in the reader, whose tag names its own file; Esc gives the reader its text back; switched from Panes, it previews where it would have (UX DESIGN O1)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ // Its reader: alpha.zig, a Look from it.
+ _ = look.open(p, held, a_path, .{ .line = 1, .col = 1 }, .replace);
+ p.sync();
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ p.view().active = held;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const reader_tag = try a.dupe(u8, try tagOf(p, a, reader));
+ const npanes = paneCount(p);
+ const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path});
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ const pk = live(p).?;
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(p.panes[reader].?.serial, pk.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
+ try std.testing.expectEqualStrings(reader_tag, try tagOf(p, a, reader));
+ try std.testing.expectEqual(@as(i32, 2), p.panes[reader].?.body.cur_row);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ try std.testing.expect(p.panes[reader].?.file.?.output == null);
+ // Panes first, from the held pane: nothing set aside; then M-h r,
+ // Recent, previews in the reader as a list opened there would.
+ open(p, held, .panes, "", "", "");
+ try std.testing.expectEqual(p.panes[held].?.serial, live(p).?.landing);
+ p.update(.{ .key = .{ .cp = 'h', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'r', .text = "r" } });
+ try std.testing.expectEqual(Source.recent, live(p).?.source);
+ try std.testing.expectEqual(p.panes[reader].?.serial, live(p).?.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+}
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 49a9645d..d5f9a374 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -124,24 +124,28 @@ pub const Ring = struct {
const Info = struct {
/// Its key cell.
cell: []const u8,
- hint: []const u8,
};
const info = std.EnumArray(Op, Info).init(.{
- .search = .{ .cell = "/", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" },
- .search_back = .{ .cell = "?", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" },
- .select = .{ .cell = "s", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" },
- .split = .{ .cell = "S", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" },
- .keep = .{ .cell = "K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" },
- .remove = .{ .cell = "A-K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" },
- .pipe = .{ .cell = "|", .hint = "⏎ replace · C-r history · esc" },
- .pipe_to = .{ .cell = "A-|", .hint = "⏎ run · C-r history · esc" },
- .insert = .{ .cell = "!", .hint = "⏎ insert · C-r history · esc" },
- .append = .{ .cell = "A-!", .hint = "⏎ append · C-r history · esc" },
- .keep_pipe = .{ .cell = "$", .hint = "⏎ keep · C-r history · esc" },
- .command = .{ .cell = ":", .hint = "Tab complete · ⏎ run · C-r history · esc" },
+ .search = .{ .cell = "/" },
+ .search_back = .{ .cell = "?" },
+ .select = .{ .cell = "s" },
+ .split = .{ .cell = "S" },
+ .keep = .{ .cell = "K" },
+ .remove = .{ .cell = "A-K" },
+ .pipe = .{ .cell = "|" },
+ .pipe_to = .{ .cell = "A-|" },
+ .insert = .{ .cell = "!" },
+ .append = .{ .cell = "A-!" },
+ .keep_pipe = .{ .cell = "$" },
+ .command = .{ .cell = ":" },
});
+/// Every prompt's one hint (UX DESIGN O4): the key to what its head and
+/// band do not show. Enter's verb is the head's own `= Look /dirty/`;
+/// M-Enter and Tab are in Help; Esc is never hinted.
+const hint = "C-r history";
+
/// The history `op` reads and Enter adds to.
fn ring(p: *Pardes, op: Op) *Ring {
return switch (op) {
@@ -846,7 +850,6 @@ pub fn execWord(p: *Pardes, id: usize) void {
/// The span of pane `pane`'s tag its search word takes while its places no
/// longer light it (the first Esc cleared them): drawn dimmed (draw.zig).
pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize {
- if (Trail.outOfRest(p, pane)) return null;
const t = &pane.trail;
const whole = pardes.tagline.folded(p, pane).whole;
for (t.steps[0..t.backs()], 0..) |*step, i| if (step.* == .search) {
@@ -1098,7 +1101,7 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_:
}
/// The head of the prompt's tag: `s self▌ = Exec Edit x/self/ 4
-/// selections in 6 lines ⏎ select · M-⏎ as a list · C-r history · esc`.
+/// selections in 6 lines C-r history`.
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
const s = &p.view().tag_state;
const pr = &s.prompt;
@@ -1140,7 +1143,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
}
if (pr.op == .command) try Command.count(p, arena, text);
const hints = text.items.len;
- const hint = info.get(pr.op).hint;
if (tail) |t| {
// Both beside the count, or neither: as much room as the right
// block asks for its two gaps (Builder.right drops the hints alone).
@@ -1369,6 +1371,12 @@ fn tagOf(p: *Pardes) ![]const u8 {
return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
}
+/// The head under the active pane's tag (UX DESIGN M2); none at rest.
+fn headOf(p: *Pardes) ![]const u8 {
+ const h = try TagState.head(p, p.scratch.allocator(), p.panes[p.view().active].?);
+ return if (h) |made| made.text else "";
+}
+
/// Whether `needle` is in `hay`, a run of two spaces or more in either read
/// as two: a right block's padding is its row's (UX D3).
fn has(hay: []const u8, needle: []const u8) bool {
@@ -1397,21 +1405,22 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the
try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
// No chip on the notice band: the prompt is the tag's.
try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
- try std.testing.expect(has(try tagOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc"));
+ // Its one hint at the row's end (UX DESIGN O4).
+ try std.testing.expect(std.mem.startsWith(u8, try headOf(p), "s ") and std.mem.endsWith(u8, try headOf(p), " C-r history"));
typeKeys(p, "self");
- try std.testing.expect(has(try tagOf(p), "s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select"));
+ try std.testing.expect(has(try headOf(p), "s self = Exec Edit x/self/ ") and has(try headOf(p), "2 selections in 3 lines C-r history"));
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
try std.testing.expect(selecting(p, pane).?.dim == false);
// No match: 0, and the selection it began with.
typeKeys(p, "x");
- try std.testing.expect(has(try tagOf(p), "= Exec Edit x/selfx/ 0 "));
+ try std.testing.expect(has(try headOf(p), "= Exec Edit x/selfx/ 0 "));
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
p.update(.{ .key = .{ .cp = Key.backspace } });
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
// No regex: the two from before, dimmed, and why.
typeKeys(p, "(");
// Its reason in place of the hints (UX D14), what follows it dim.
- try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " bad regular expression · the 2 from before shown, dimmed"));
+ try std.testing.expect(std.mem.endsWith(u8, try headOf(p), " bad regular expression · the 2 from before shown, dimmed"));
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
try std.testing.expect(selecting(p, pane).?.dim);
// Esc: rest, the tag and the selection as they were.
@@ -1439,10 +1448,10 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba
typeKeys(p, "K");
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("self..", p.view().tag_state.field.text());
- try std.testing.expect(has(try tagOf(p), "K self.. = Exec Edit g/self../ keeps 2 of 2"));
+ try std.testing.expect(has(try headOf(p), "K self.. = Exec Edit g/self../ keeps 2 of 2"));
p.update(.{ .key = .{ .cp = Key.down } });
typeKeys(p, "b");
- try std.testing.expect(has(try tagOf(p), "K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep"));
+ try std.testing.expect(has(try headOf(p), "K b = Exec Edit g/b/ ") and has(try headOf(p), "keeps 1 of 2 C-r history"));
// Ctrl-r: the history under the tag, a row a line.
p.update(.{ .key = .{ .cp = 'r', .ctrl = true } });
try std.testing.expectEqual(@as(u16, 1), Band.takes(p, p.view().active));
@@ -1454,7 +1463,7 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba
typeKeys(p, "|");
try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
- try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
+ try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ") and has(try headOf(p), "⋯ C-r history"));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?);
var asked: ?u32 = null;
@@ -1491,9 +1500,9 @@ test "/ searches the body as it is typed: the current place selected, `▸` in t
pane.body.cur_row = 2;
pane.body.cur_col = 6;
typeKeys(p, "/dirty");
- try std.testing.expect(has(try tagOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list"));
+ try std.testing.expect(has(try headOf(p), "/ dirty = Look /dirty/ ") and has(try headOf(p), "3/7 · 5 lines C-r history"));
try std.testing.expectEqual(@as(?usize, 2), pane.places.current);
- try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 0));
+ // (Its first row under the head's, UX DESIGN M2.)
try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1));
try std.testing.expectEqualStrings("▸", try gutterAt(p, frame.allocator(), 2));
try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 7));
@@ -1504,8 +1513,9 @@ test "/ searches the body as it is typed: the current place selected, `▸` in t
const x = r.x + config.GUTTER + File.gutterWidth(pane);
const y = p.bodyTop(pane, r);
try std.testing.expectEqual(pardes.Color{ .rgb = c.page.key }, s.at(x - 1 - File.laneCells(pane) - pane.layers.heat, y + 2).style.fg);
- // Line 1's place (`dirty` at its start) on the hit ground.
- try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, s.at(x, y).style.bg);
+ // Line 5's place (`dirty` at its start) on the hit ground (line 1's
+ // under the head's row, UX DESIGN M2).
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, s.at(x, y + 4).style.bg);
}
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
@@ -1548,13 +1558,13 @@ test "? searches back from the caret; no match is 0; a pattern that is no regex
pane.body.cur_col = 6;
const was = pane.body.primaryRange(pane.file.?.content, 0);
typeKeys(p, "?dirty");
- try std.testing.expect(has(try tagOf(p), "? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land"));
+ try std.testing.expect(has(try headOf(p), "? dirty = Look ?dirty? ") and has(try headOf(p), "2/7 · 5 lines C-r history"));
typeKeys(p, "x");
- try std.testing.expect(has(try tagOf(p), "= Look ?dirtyx? 0 ⏎ land"));
+ try std.testing.expect(has(try headOf(p), "= Look ?dirtyx? ") and has(try headOf(p), "0 C-r history"));
try std.testing.expectEqualDeep(was, pane.body.primaryRange(pane.file.?.content, 0));
p.update(.{ .key = .{ .cp = Key.backspace } });
typeKeys(p, "(");
- try std.testing.expect(has(try tagOf(p), " bad regular expression · "));
+ try std.testing.expect(has(try headOf(p), " bad regular expression · "));
try std.testing.expect(dims(p, pane) and pane.places.started);
try std.testing.expectEqualStrings("dirty", pane.places.pattern);
p.update(.{ .key = .{ .cp = Key.escape } });
@@ -1585,7 +1595,8 @@ test "sam prompts one after another make one recipe word, the Edit line it is; a
try std.testing.expectEqual(@as(usize, 29), @max(back.anchor, back.head));
// A motion ends it: the next s is a recipe of its own, the pane's one.
typeKeys(p, "j%sself..");
- for ([_]u16{ 0, 1, 2 }) |row| try std.testing.expectEqualStrings("┃", try gutterAt(p, frame.allocator(), row));
+ // (Its first row under the head's, UX DESIGN M2.)
+ for ([_]u16{ 1, 2 }) |row| try std.testing.expectEqualStrings("┃", try gutterAt(p, frame.allocator(), row));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "Edit x/self../ › /test.txt "));
try std.testing.expectEqual(@as(u8, 1), pane.trail.n);
@@ -1636,23 +1647,24 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho
p.update(.{ .key = .{ .cp = Key.enter } });
typeKeys(p, "|");
p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
- try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace"));
+ try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ") and has(try headOf(p), "⋯ C-r history"));
const first = lastPipe(p) orelse return error.MissingLiveRun;
const asked = p.pipe.pipeRequest(first).?;
try std.testing.expectEqual(@as(usize, 2), asked.inputs.len);
try std.testing.expect(has(asked.command, "tr a-z A-Z") and has(asked.command, "\\036"));
p.update(.{ .pipe_resp = .{ .id = first, .success = true, .outputs = &.{ "B\x1e\x1e0", "A\x1e\x1e0" } } });
- try std.testing.expect(has(try tagOf(p), " 2 lines → 2 · exit 0 ⏎ replace"));
+ try std.testing.expect(has(try headOf(p), "2 lines → 2 · exit 0 C-r history"));
// The body: each output a ghost line under the line it replaces, the
- // rows below pushed down; the text as it was.
+ // rows below pushed down; the text as it was; its first row under the
+ // head's (UX DESIGN M2).
p.sync();
const s = try p.render(frame.allocator());
const r = p.view().rects[0];
const x = r.x + config.GUTTER + File.gutterWidth(pane);
const y = p.bodyTop(pane, r);
- for ([_][]const u8{ "b", "B", "a", "A", "c" }, 0..) |want, row| try std.testing.expectEqualStrings(want, s.at(x, y + @as(u16, @intCast(row))).grapheme());
+ for ([_][]const u8{ "B", "a", "A", "c" }, 1..) |want, row| try std.testing.expectEqualStrings(want, s.at(x, y + @as(u16, @intCast(row))).grapheme());
// On the chrome's diff rows (R10), the ghost in the page's text.
- try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().del.row }, s.at(x, y).style.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().del.row }, s.at(x, y + 2).style.bg);
try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().add.row }, s.at(x, y + 1).style.bg);
try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.text }, s.at(x, y + 1).style.fg);
try std.testing.expectEqualStrings("b\na\nc\n", pane.file.?.content);
@@ -1663,16 +1675,16 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho
// No known filter: not run until C-p.
typeKeys(p, "|");
p.update(.{ .key = .{ .cp = 'r', .text = "rot13" } });
- try std.testing.expect(has(try tagOf(p), " rot13 isn't a known filter · C-p runs it"));
+ try std.testing.expect(has(try headOf(p), " rot13 isn't a known filter · C-p runs it"));
try std.testing.expect(lastPipe(p) == null);
p.update(.{ .key = .{ .cp = 'p', .ctrl = true } });
const second = lastPipe(p) orelse return error.MissingLiveRun;
p.update(.{ .pipe_resp = .{ .id = second, .success = true, .outputs = &.{ "\x1eoops: no\x1e2", "X\x1e\x1e0" } } });
- try std.testing.expect(has(try tagOf(p), " 2 runs · 1 ok · 1 exit 2 oops: no "));
+ try std.testing.expect(has(try headOf(p), " 2 runs · 1 ok · 1 exit 2 oops: no "));
// Enter refused once, said; again, the one that worked applied.
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
- try std.testing.expect(has(try tagOf(p), "oops: no — ⏎ again applies the 1 that worked"));
+ try std.testing.expect(has(try headOf(p), "oops: no — ⏎ again applies the 1 that worked"));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
try std.testing.expectEqualStrings("B\nX\nc\n", pane.file.?.content);
@@ -1783,7 +1795,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it
const h = try head(p, p.scratch.allocator(), pane);
const lines = std.mem.indexOf(u8, h.text, " \u{b7} 5 lines");
if (cols == 200) {
- try std.testing.expect(has(h.text, "3/7 \u{b7} 5 lines \u{23ce} land"));
+ try std.testing.expect(has(h.text, "3/7 \u{b7} 5 lines C-r history"));
const dim = for (h.spans) |span| {
if (span.lo == lines.? and span.style == .dim) break span;
} else return error.TestUnexpectedResult;
@@ -1791,7 +1803,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it
} else {
// No room for the hints: the count alone, at the row's end.
try std.testing.expect(lines == null);
- try std.testing.expect(std.mem.indexOf(u8, h.text, "\u{23ce} land") == null);
+ try std.testing.expect(std.mem.indexOf(u8, h.text, "C-r history") == null);
try std.testing.expect(std.mem.endsWith(u8, h.text, "3/7"));
}
}
@@ -1802,7 +1814,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it
pane.body.cur_row = 7;
pane.body.cur_col = 6;
typeKeys(p, "/dirty");
- try std.testing.expect(has(try tagOf(p), "1/7 \u{21bb} \u{b7} 5 lines \u{23ce} land"));
+ try std.testing.expect(has(try headOf(p), "1/7 \u{21bb} \u{b7} 5 lines C-r history"));
}
test "C-r's history has the band's cursor like any list (UX D5): `▶` on its newest line, Down and C-n, Up and C-p move it, Enter takes the line under it" {
diff --git a/core/Query.zig b/core/Query.zig
index f9651faf..96047ca1 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -749,6 +749,8 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self:
for (p.panes) |slot| {
const other = slot orelse continue;
if (other == self or other.query != null) continue;
+ // A picker's preview is no pane to go to (UX DESIGN O1).
+ if (other.file) |f| if (f.output) |o| if (o.from == .preview) continue;
var buf: [4096 + 32]u8 = undefined;
const what: []const u8 = if (other.file) |f| f.path else if (other.command) |c| c else other.cwdSlice();
const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, relative(what, dir) }) catch continue;
diff --git a/core/TagState.zig b/core/TagState.zig
index c754e468..468c7895 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -7,9 +7,10 @@
//! the level shows, whether it is unrolled, its cursor, the key it missed,
//! and the leaf each group ran last.
//!
-//! The head (keys, level words, hints) is computed tag text drawn after
-//! the prefix in place of the tag's own text (R1), never written into it:
-//! `head`, which tagline.zig's `shownTail` reads.
+//! The head (keys, level words, the field, the count, hints) is computed
+//! text hanging on the rows under the tag, which stays as at rest (UX
+//! DESIGN M): `head`, which the band draws as its first rows (draw.zig
+//! joinBand), never written into the tag.
const TagState = @This();
const std = @import("std");
@@ -80,6 +81,14 @@ miss: u8 = 0,
/// The leaf each group ran last, by its key (bindings.groups): the cursor
/// starts there and the rolled level underlines it (SPEC §4.3).
used: [bindings.ngroups]u8 = @splat(0),
+/// A state with a field (Help, a picker, a text prompt, `:`, rename) whose
+/// pane lost the keyboard to a click elsewhere (UX DESIGN O2): unrolled as
+/// it was, its field drawn with no caret and its pane's box saying its
+/// mode; keys go where the keyboard is, Esc ends it first, and a click on
+/// its head or band, or a key that moves the keyboard back to its pane,
+/// gives it the keyboard again. A level, the registers and describe-key,
+/// which hold no typed text, end on such a click instead.
+waits: bool = false,
/// `.full` while the whole window previews a theme (a themes picker's
/// row, `:theme `'s): its own again at rest. No pane dims out of rest
/// (UX D9), so no pane's own bit is read.
@@ -233,6 +242,7 @@ pub fn toRest(p: *Pardes) void {
const s = &v.tag_state;
if (s.kind == .prompt) Prompt.leave(p);
s.kind = .rest;
+ s.waits = false;
// The whole window previewed `:theme `'s row (Command.preview): its
// own theme again (a themes picker's went as it rolled up).
if (s.previewing.eql(.full)) @import("colors.zig").previewTheme(p, null);
@@ -339,14 +349,16 @@ fn reaches(p: *const Pardes, root: Root, path: []const u8, leaf: bool) bool {
/// 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.
-/// A question waits on pane `pane` at rest, its keyboard not in its tag:
-/// its tag says it after the path, in place of the tag's computed words
-/// and own text (UX D13, K'3).
+/// A question waits on pane `pane`, its keyboard not in its tag: its tag
+/// says it after the path, in place of the tag's computed words and own
+/// text (UX D13, K'3), in and out of rest (UX DESIGN M1).
pub fn asks(p: *const Pardes, pane: *const Pane) bool {
return pane.focus != .tag and pane.prompt != .name and p.messages.waiting(pane) != null;
}
-fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
+/// The question pane `pane`'s tag says after its path, while one waits on
+/// it (`asks`).
+pub fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
if (!asks(p, pane)) return null;
const i = p.messages.waiting(pane).?;
const said = &p.messages.live[i];
@@ -383,9 +395,10 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
/// The keys of the root current in view `v` while its level waits for its
/// delay (UX D12: the tag is at rest until then), as the notice row's right
-/// end echoes them at once: `SPC f`.
+/// end echoes them at once: `SPC f`; all along while a state waits for the
+/// keyboard (`waits`), whose head and band stay where the level would show.
pub fn pending(p: *const Pardes, v: *const View, buf: []u8) ?[]const u8 {
- if (v.tag_state.kind != .rest or shown(p, v)) return null;
+ if (if (v.tag_state.kind == .rest) shown(p, v) else !v.tag_state.waits) return null;
const cur = current(p, v) orelse return null;
return bindings.chord(cur.root, cur.path, buf);
}
@@ -536,17 +549,15 @@ pub const Head = struct {
caret: ?u32 = null,
};
-/// A head as it is built: its text and spans, laid out against the tag's
-/// rows (UX D2, D3).
+/// A head as it is built: its text and spans, laid out against the rows
+/// under the tag, from the tag's text column (UX D2, D3, DESIGN M2).
pub const Builder = struct {
arena: std.mem.Allocator,
text: std.ArrayList(u8) = .empty,
spans: std.ArrayList(Span) = .empty,
cells: u8 = 0,
- /// The cells of a row of the tag, and those before the head on its
- /// first row (the owner's and the newest step's words).
+ /// The cells of a row of the tag.
width: usize = 0,
- lead: usize = 0,
tab: u16 = 8,
/// Each key cell's column, which a spine hangs under (UX D5).
cols: [Band.max_spines]u16 = undefined,
@@ -554,9 +565,8 @@ pub const Builder = struct {
/// A head for pane `pane`'s tag, out of rest in the live view.
pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Builder {
- const prefix = try tagline.prefixIn(p, arena, pane);
const id = panes.paneIdOf(p, pane) orelse 0;
- return .{ .arena = arena, .width = tagline.tagWidth(p, id), .lead = panes.File.displayWidth(p.settings.tab, prefix), .tab = p.settings.tab };
+ return .{ .arena = arena, .width = tagline.tagWidth(p, id), .tab = p.settings.tab };
}
pub fn put(b: *Builder, s: []const u8) !void {
@@ -568,12 +578,11 @@ pub const Builder = struct {
try b.spans.append(b.arena, .{ .lo = lo, .hi = @intCast(b.text.items.len), .style = style });
}
- /// The cells the row being built takes so far, the prefix's before the
- /// first row's.
+ /// The cells the row being built takes so far.
pub fn col(b: *const Builder) usize {
const items = b.text.items;
- const nl = std.mem.lastIndexOfScalar(u8, items, '\n') orelse return b.lead + panes.File.displayWidth(b.tab, items);
- return panes.File.displayWidth(b.tab, items[nl + 1 ..]);
+ const nl = std.mem.lastIndexOfScalar(u8, items, '\n');
+ return panes.File.displayWidth(b.tab, items[if (nl) |at| at + 1 else 0..]);
}
/// The right block (UX D3): what was put from byte `count` on (the
@@ -591,7 +600,7 @@ pub const Builder = struct {
while (h > count and b.text.items[h - 1] == ' ') : (h -= 1) b.cut(h - 1, h);
const items = b.text.items;
const start = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0;
- const left = panes.File.displayWidth(b.tab, items[start..count]) + if (start == 0) b.lead else 0;
+ const left = panes.File.displayWidth(b.tab, items[start..count]);
var trail: usize = 0;
while (trail < count - start and items[count - 1 - trail] == ' ') trail += 1;
const cw = panes.File.displayWidth(b.tab, items[count..h]);
@@ -673,19 +682,18 @@ pub const Builder = struct {
}
};
-/// The head of pane `pane`'s tag while it is out of rest in the live view,
-/// or while a question waits on it at rest (`asking`); null at rest.
+/// The head under pane `pane`'s tag while it is out of rest in the live
+/// view (UX DESIGN M2); null at rest.
pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
- const id = hostOf(p) orelse return asking(p, arena, pane);
- if (p.panes[id] != pane) return asking(p, arena, pane);
+ const id = hostOf(p) orelse return null;
+ if (p.panes[id] != pane) return null;
const v = p.view();
const s = &v.tag_state;
var b = try Builder.of(p, arena, pane);
switch (s.kind) {
.rest => {},
// `Help`, its scope's keys, the field, its count at the row's end:
- // `Help ␣ l hov 2/17` (out of rest the head starts the tag's
- // text, after the owner's and the newest step's words: UX D1).
+ // `Help ␣ l hov 2/17`.
.help => {
try b.put("Help ");
if (s.scope_root) |r| try b.keyCells(r, s.scope[0..s.scope_n]);
@@ -722,14 +730,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
try b.put(" ");
try b.put(c.label);
};
- const hints = b.text.items.len;
- try b.styled("⏎ run · esc", .dim);
- try b.right(hints, hints);
} else try b.put("…");
} else {
+ // The state's question, not a hint (UX DESIGN O4).
try b.put("…");
const hints = b.text.items.len;
- try b.styled("press a key or a sequence · esc", .dim);
+ try b.styled("press a key or a sequence", .dim);
try b.right(hints, hints);
}
return b.done();
@@ -737,7 +743,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
.pick => return @import("Pick.zig").head(p, arena, pane),
.prompt => return try Prompt.head(p, arena, pane),
// `Rename`, the name under the caret struck, the new one typed:
- // `Rename best → top▌ ⏎ rename · esc` (SPEC §3.5).
+ // `Rename best → top▌` (SPEC §3.5), no hint (UX DESIGN O4).
.rename => {
try b.put("Rename ");
try b.styled(Ask.renamedWord(pane) orelse "", .strike);
@@ -745,9 +751,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
var h = b.done();
h.caret = @intCast(b.text.items.len + s.field.caret);
try b.put(s.field.text());
- const hints = b.text.items.len;
- try b.styled("⏎ rename · esc", .dim);
- try b.right(hints, hints);
h.text = b.text.items;
h.spans = b.spans.items;
return h;
@@ -756,10 +759,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
const cur = current(p, v) orelse return null;
try b.keyCells(cur.root, cur.path);
const node = bindings.nodeAt(cur.root, cur.path) orelse return b.done();
+ // One hint, a level's and the registers' (UX DESIGN O4): `? help`.
+ const hint = "? help";
if (s.unrolled) {
try b.put(if (cur.path.len == 0) bindings.info.get(cur.root).label else node.label);
const hints = b.text.items.len;
- try b.styled("↑ roll up · ? field · esc", .dim);
+ try b.styled(hint, .dim);
try b.right(hints, hints);
return b.done();
}
@@ -767,9 +772,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
// The rolled level breaks between its children only (UX D2), each row
// after the first from the first child's column, its spines on through
// it; three rows at most, the last ending `+N ↓` (N the children not
- // shown, `↓` unrolls them) when they do not fit. Rows past the tag's
- // own are drawn over the body (UX DESIGN I1), a terminal's too: its pty
- // keeps its size.
+ // shown, `↓` unrolls them) when they do not fit. They hang under the
+ // tag over the body (UX DESIGN I1, M2), a terminal's too: its pty keeps
+ // its size.
const tab = p.settings.tab;
const most: usize = 3;
var children: [bindings.max_children]bindings.Child = undefined;
@@ -793,7 +798,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
// level that wraps gives them its spare row, its last child going to
// it to leave them room; a level of one row or of all its rows keeps
// its rows, and they drop where they do not fit.
- const hint = "↓ unroll · ? help";
const hinted = 2 + panes.File.displayWidth(tab, hint);
var rows: usize = 1;
for (level, 0..) |c, i| {
@@ -843,8 +847,12 @@ fn more(n: usize, last: bool) usize {
return 5 + std.fmt.count("{d}", .{n});
}
+/// What a test reads of the active pane: out of rest its head, hanging
+/// under its tag (UX DESIGN M2); at rest its tag, which no state changes.
fn testTag(p: *Pardes, arena: std.mem.Allocator) ![]const u8 {
- return tagline.tagText(p, arena, p.panes[p.view().active].?);
+ const pane = p.panes[p.view().active].?;
+ if (try head(p, arena, pane)) |h| return h.text;
+ return tagline.tagText(p, arena, pane);
}
test "SPC changes nothing in the tag until its level shows 250 ms on, its keys on the notice row's right end at once; g nothing until 500 ms, and gg never" {
@@ -876,6 +884,8 @@ test "SPC changes nothing in the tag until its level shows 250 ms on, its keys o
p.clock.now_ns = due - 1;
try std.testing.expectEqualStrings(rest, try testTag(p, a));
p.clock.now_ns = due;
+ // The level under the tag, the tag as it was (UX DESIGN M1).
+ try std.testing.expectEqualStrings(rest, try tagline.tagText(p, a, p.panes[p.view().active].?));
const level = try testTag(p, a);
try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null);
try std.testing.expect(std.mem.indexOf(u8, level, "l lsp…") != null);
@@ -952,14 +962,14 @@ test "the right block: the count `cursor/matches` at the row's right end, fixed
p.update(.{ .key = .{ .cp = Key.down } });
row = firstRow(try testTag(p, a));
try std.testing.expect(std.mem.startsWith(u8, row, "␣ SPC "));
- try std.testing.expect(std.mem.endsWith(u8, row, " ↑ roll up · ? field · esc"));
+ try std.testing.expect(std.mem.endsWith(u8, row, " ? help"));
try std.testing.expectEqual(width, panes.File.displayWidth(tab, row));
const h = (try head(p, a, p.panes[p.view().active].?)).?;
const last = h.spans[h.spans.len - 1];
try std.testing.expect(last.style == .dim and last.hi == h.text.len);
p.update(.{ .key = .{ .cp = Key.escape } });
// Where the row has no room for them, the hints go whole.
- const narrow = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 24, .rows = 30 });
+ const narrow = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 14, .rows = 30 });
defer narrow.deinit();
_ = try narrow.setTestFile("one\n");
narrow.update(.{ .key = .{ .cp = ' ' } });
@@ -1010,7 +1020,7 @@ test "a rolled level breaks between its children only: the rows after the first
whole += 1;
}
try std.testing.expect(whole > 0 and whole < level.len);
- try std.testing.expect(std.mem.endsWith(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole})));
+ try std.testing.expect(std.mem.indexOf(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole})) != null);
// A level that fits takes one row; its hints at its end where the row
// has room for them, else none.
p.update(.{ .key = .{ .cp = 'h' } });
@@ -1315,7 +1325,7 @@ test "a band over a terminal is drawn over its body's top rows: its pty keeps it
_ = try p.render(frame.allocator());
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
try std.testing.expect(layer.kind == .band and layer.rows > 0);
- try std.testing.expectEqual(p.tagTop(pane, p.view().rects[shell]) + pardes.Band.covered(p, pane, shell).text, layer.viewport.y);
+ try std.testing.expectEqual(p.tagTop(pane, p.view().rects[shell]) + pardes.Band.covered(p, pane, shell).tag, layer.viewport.y);
p.update(.{ .key = .{ .cp = Key.escape } });
p.sync();
try std.testing.expectEqual(rows, pane.rows);
@@ -1333,14 +1343,15 @@ test "a tag out of rest keeps exactly its rows at rest: a level shorter than its
p.sync();
const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
try std.testing.expect(tag_rows > 1);
- // Help's head, a row, its band from the row under it: the rows the tag
- // keeps from rest are the band's first (UX E3), the rest drawn over the
- // body, which keeps its rows (UX DESIGN I1).
+ // Help's head, a row under the tag's, its band under that, drawn over
+ // the body, which keeps its rows (UX DESIGN I1, M2).
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = '?' } });
p.sync();
try std.testing.expect(hostOf(p) != null);
- try std.testing.expectEqual(@as(u16, 1), pardes.Band.covered(p, pane, p.view().active).text);
+ const at = pardes.Band.covered(p, pane, p.view().active);
+ try std.testing.expectEqual(@as(u16, 1), at.head);
+ try std.testing.expectEqual(tag_rows, at.tag);
try std.testing.expectEqual(tag_rows, pane.tag_rows);
try std.testing.expectEqual(rows, pane.rows);
// With the keyboard in the tag (whose top row follows its caret) too:
@@ -1384,7 +1395,7 @@ test "a dump's tag state that indexes past what it names is at rest when loaded,
try std.testing.expect(s.kind == .rest);
}
-test "a click that gives the keyboard to another pane ends a level as Esc does; one in the level's own tag keeps it" {
+test "a click that gives the keyboard to another pane ends a level as Esc does; one in the level's own tag ends it too, then does what it does there at rest; Help and a text prompt, which hold a field, wait instead, and a word run in their pane's tag leaves them up (UX DESIGN M3, O2)" {
const config = @import("config.zig");
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
defer p.deinit();
@@ -1401,13 +1412,38 @@ test "a click that gives the keyboard to another pane ends a level as Esc does;
}.at;
const rt = p.view().rects[top];
const rl = p.view().rects[low];
- // SPC's level in the lower pane's tag; a click in its own tag keeps it.
+ // The lower pane's own text a word, Wrap.
+ p.panes[low].?.tag.own = try p.gpa.dupe(u8, "Wrap");
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const tag = try tagline.tagText(p, frame.allocator(), p.panes[low].?);
+ const word: u16 = rl.x + pardes.TAG_TEXT_INSET + 1 + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, tag[0..std.mem.indexOf(u8, tag, "Wrap").?])));
+ // SPC's level under its tag; a click in its own tag ends it as Esc
+ // does, then gives the tag the keyboard, as at rest.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ try std.testing.expect(hostOf(p) == low);
+ click(p, word, rl.y);
+ try std.testing.expect(hostOf(p) == null and p.view().prefix == .none);
+ try std.testing.expectEqual(Pane.Focus.tag, p.panes[low].?.focus);
+ // Help, which holds a field: B2 on the word runs it, Help up.
+ p.panes[low].?.focus = .body;
+ for (" ?") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().tag_state.kind == .help and hostOf(p) == low);
+ const wrapped = p.settings.wrap;
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = word, .row = rl.y } });
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = word, .row = rl.y } });
+ try std.testing.expect(p.view().tag_state.kind == .help and hostOf(p) == low);
+ try std.testing.expect(p.settings.wrap != wrapped);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(p.view().tag_state.kind == .rest);
+ // SPC's level again, for the clicks elsewhere.
p.update(.{ .key = .{ .cp = ' ' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
try std.testing.expect(hostOf(p) == low);
- click(p, rl.x + config.GUTTER + 2, rl.y);
- try std.testing.expect(hostOf(p) == low and p.view().prefix == .leader);
// A click in the other pane's body: the keyboard goes there, the level
// ends, nothing out of rest.
click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
@@ -1425,7 +1461,19 @@ test "a click that gives the keyboard to another pane ends a level as Esc does;
for (" ?") |c| p.update(.{ .key = .{ .cp = c } });
try std.testing.expect(p.view().tag_state.kind == .help);
click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
- try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null);
+ try std.testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.waits and hostOf(p) == low);
+ try std.testing.expectEqual(top, p.view().active);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(p.view().tag_state.kind == .rest and !p.view().tag_state.waits);
+ // A text prompt, `s` in the lower pane's text: it waits the same.
+ p.view().active = low;
+ p.update(.{ .key = .{ .cp = '%', .text = "%" } });
+ p.update(.{ .key = .{ .cp = 's', .text = "s" } });
+ try std.testing.expect(p.view().tag_state.kind == .prompt and hostOf(p) == low);
+ click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
+ try std.testing.expect(p.view().tag_state.kind == .prompt and p.view().tag_state.waits and hostOf(p) == low);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(p.view().tag_state.kind == .rest);
}
test "a rolled level that wraps has its hints on its last row at every width that leaves it a row to spare: `]` and `g` as SPC (UX D3)" {
@@ -1442,7 +1490,7 @@ test "a rolled level that wraps has its hints on its last row at every width tha
p.clock.now_ns = p.view().tag_state.due_ns;
try std.testing.expect(hostOf(p) != null);
const tag = try testTag(p, a);
- if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ↓ unroll · ? help"));
+ if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ? help"));
p.update(.{ .key = .{ .cp = pardes.Key.escape } });
try std.testing.expect(hostOf(p) == null);
};
@@ -1626,3 +1674,148 @@ test "a tag state a session made loads as it was, its digest the session's: Help
try std.testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.found);
try same(p);
}
+
+/// Row `y` of surface `s` from column `x`, `w` cells, as text.
+fn gridRow(a: std.mem.Allocator, s: *const pardes.Surface, x: u16, y: u16, w: u16) ![]const u8 {
+ var out: std.ArrayList(u8) = .empty;
+ for (s.cells[@as(usize, y) * s.cols + x ..][0..w]) |cell| try out.appendSlice(a, cell.grapheme());
+ return out.items;
+}
+
+/// A reading pane in a work tree of its own that walked from `near.txt` to
+/// `far.txt` (a place on its trail), the keyboard in its body.
+fn walkedReader(p: *Pardes, tmp: *std.testing.TmpDir) !usize {
+ tmp.dir.createDir(std.testing.io, ".git", .default_dir) catch |err| if (err != error.PathAlreadyExists) return err;
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "near.txt", .data = "one\ntwo\nthree\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "far.txt", .data = "four\nfive\n" });
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var path: [std.Io.Dir.max_path_bytes + 16]u8 = undefined;
+ @import("look.zig").lookAt(p, p.view().active, try std.fmt.bufPrint(&path, "{s}/near.txt:2", .{dir}));
+ p.sync();
+ @import("look.zig").lookAt(p, p.view().active, try std.fmt.bufPrint(&path, "{s}/far.txt", .{dir}));
+ p.sync();
+ const id = p.view().active;
+ p.panes[id].?.focus = .body;
+ return id;
+}
+
+test "out of rest a tag is drawn as at rest, the head hanging under it (UX DESIGN M1, M2): a picker in a reading pane with a trail keeps every cell of the tag's rows but the box and its path's ink, the path its own and dim while the body previews another file; the head on the next row, the count its last cells; the band's rows under it; Esc, the tag as it was" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const id = try walkedReader(p, &tmp);
+ const pane = p.panes[id].?;
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const rest = try gpa.dupe(u8, try tagline.tagText(p, a, pane));
+ defer gpa.free(rest);
+ try std.testing.expect(std.mem.indexOf(u8, rest, "near.txt") != null and std.mem.indexOf(u8, rest, "far.txt Keep") != null);
+ const r = p.view().rects[id];
+ const tag_y = p.tagTop(pane, r);
+ const tag_rows = pane.tag_rows;
+ const before = try gpa.dupe(pardes.Cell, (try p.render(a)).cells);
+ defer gpa.free(before);
+ const cols = p.surface.cols;
+ // A list whose row is a place in near.txt: the body previews it.
+ pardes.Pick.open(p, id, .list, "Refs", "", "near.txt:3:1 three\n");
+ p.update(.tick);
+ try std.testing.expectEqual(@as(?usize, id), hostOf(p));
+ try std.testing.expect(std.mem.endsWith(u8, pane.file.?.path, "near.txt"));
+ try std.testing.expectEqualStrings(rest, try tagline.tagText(p, a, pane));
+ _ = frame.reset(.retain_capacity);
+ const s = try p.render(a);
+ // The tag's rows: every cell as at rest but the box's, which says the
+ // tag is typed in, and its path's ink: the body previews near.txt, not
+ // the far.txt the path names, so the path is in the dim ink (draw.zig
+ // paintPaneTag, the coordinator's ruling, UX DESIGN M7.2); where a
+ // column's other panes gave the picker rows (UX D6), the pane's top is
+ // higher, its tag the same.
+ const now = p.view().rects[id];
+ const now_y = p.tagTop(pane, now);
+ try std.testing.expectEqual(r.w, now.w);
+ try std.testing.expectEqualStrings("^", s.at(now.x, now_y).grapheme());
+ const dim: pardes.Color = .{ .rgb = p.chrome().on(.focus).dim };
+ var dimmed: std.ArrayList(u8) = .empty;
+ defer dimmed.deinit(gpa);
+ for (0..tag_rows) |row| for (1..r.w) |col| {
+ const was = before[(tag_y + row) * cols + r.x + col];
+ var is = s.cells[(now_y + row) * cols + now.x + col];
+ if (!std.meta.eql(was, is) and std.meta.eql(is.style.fg, dim)) {
+ try dimmed.appendSlice(gpa, is.grapheme());
+ is.style.fg = was.style.fg;
+ }
+ try std.testing.expect(std.meta.eql(was, is));
+ };
+ try std.testing.expect(std.mem.endsWith(u8, dimmed.items, "/far.txt"));
+ // The head: the row under the tag, from the tag's text column; its count
+ // the row's last cells.
+ const head_y: u16 = @intCast(now_y + tag_rows);
+ const row = try gridRow(a, s, r.x + pardes.TAG_TEXT_INSET, head_y, r.w - pardes.TAG_TEXT_INSET);
+ try std.testing.expect(std.mem.startsWith(u8, row, "␣ l Refs "));
+ try std.testing.expect(std.mem.endsWith(u8, row, " 1/1 M-l acts"));
+ // The band's first row under the head's: the list's row, its cursor's.
+ const band_y: u16 = head_y + Band.covered(p, pane, id).head;
+ try std.testing.expect(std.mem.indexOf(u8, try gridRow(a, s, r.x + pardes.TAG_TEXT_INSET, band_y, r.w - pardes.TAG_TEXT_INSET), "▶ near.txt:3") != null);
+ // Esc: the tag as it was, the box's mode back, no row under it, the
+ // pane where it was.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(hostOf(p) == null);
+ try std.testing.expectEqualStrings(rest, try tagline.tagText(p, a, pane));
+ _ = frame.reset(.retain_capacity);
+ const back = try p.render(a);
+ for (tag_y..tag_y + tag_rows + 1) |y| for (r.x..r.x + r.w) |x| {
+ const i = y * cols + x;
+ try std.testing.expect(std.meta.eql(before[i], back.cells[i]));
+ };
+}
+
+test "the key cells are one thing growing on the row under the tag (UX DESIGN M1): `␣`, then `␣ f`, then the picker's `␣ f Find`, each key in the same cell, from SPC's level to its picker, under a tag of two rows" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 });
+ defer p.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const id = try walkedReader(p, &tmp);
+ const pane = p.panes[id].?;
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.sync();
+ try std.testing.expect(pane.tag_rows > 1);
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const r = p.view().rects[id];
+ const x = r.x + pardes.TAG_TEXT_INSET;
+ const y: u16 = @intCast(p.tagTop(pane, r) + pane.tag_rows);
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ var s = try p.render(frame.allocator());
+ try std.testing.expectEqualStrings("␣", s.at(x, y).grapheme());
+ try std.testing.expectEqualStrings("▸", s.at(x + 2, y).grapheme());
+ // (A picker takes rows from its column's other panes: the row under its
+ // tag where its pane is then, UX D6.)
+ p.update(.{ .key = .{ .cp = 'f' } });
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqualStrings("␣", s.at(x, y).grapheme());
+ try std.testing.expectEqualStrings("f", s.at(x + 2, y).grapheme());
+ try std.testing.expectEqualStrings("▸", s.at(x + 4, y).grapheme());
+ p.update(.{ .key = .{ .cp = 'f' } });
+ try std.testing.expectEqual(Kind.pick, p.view().tag_state.kind);
+ try std.testing.expectEqual(@as(?usize, id), hostOf(p));
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ const now = p.view().rects[id];
+ try std.testing.expectEqual(r.x, now.x);
+ const row = try gridRow(frame.allocator(), s, x, @intCast(p.tagTop(pane, now) + Band.covered(p, pane, id).tag), r.w - pardes.TAG_TEXT_INSET);
+ try std.testing.expect(std.mem.startsWith(u8, row, "␣ f Find "));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
diff --git a/core/Trail.zig b/core/Trail.zig
index cd115018..e10f4fed 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -28,8 +28,7 @@ pub const max_steps = 16;
/// The bytes of a step's path or word. A jump to a longer path is no step:
/// it opens a pane as `Jumps new-pane` does (look.zig open).
pub const max_text = 256;
-/// The newest back steps written whole at rest; older ones fold to `·`
-/// (§6.3). Out of rest the owner's and the newest alone (`.newest`).
+/// The newest back steps written whole; older ones fold to `·` (§6.3).
pub const shown_steps = 3;
/// `cur` held to the steps there are (walk.zig `.place`).
@@ -76,9 +75,15 @@ pub fn isFile(pane: *const Pane) bool {
return f.output == null and f.listing == null and !f.pager and f.mini == null and pane.query == null and pane.addon == null;
}
-/// A pane that walks: a file not held, in a session whose jumps walk.
+/// A pane that walks: a file not held, in a session whose jumps walk. A
+/// picker's preview in its body changes nothing: its own file, set aside
+/// under the preview, is the one asked of (tagline.named: its tag and its
+/// tint stay as at rest, UX DESIGN M1).
pub fn reading(p: *const Pardes, pane: *const Pane) bool {
- return p.settings.jumps == .walk and isFile(pane) and !pane.trail.held;
+ if (p.settings.jumps != .walk or pane.trail.held) return false;
+ if (pardes.Pick.landingOf(p, pane) == null) return isFile(pane);
+ const f = pardes.tagline.named(p, pane) orelse return false;
+ return f.output == null and f.listing == null and !f.pager and f.mini == null and pane.query == null;
}
/// An untouched pane (UX J1): a `+New` never typed into (no undo
@@ -237,6 +242,9 @@ pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
/// pane is held, as Keep holds it, and the step opens where a held pane's
/// go, in its reader.
fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
+ // A step in the pane a picker asks from or previews in ends the picker
+ // first, as Esc does (UX DESIGN O3): the step is from its own text.
+ pardes.Pick.yieldFor(p, id);
const pane = p.panes[id].?;
if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) {
look.clearNavigationSelection(p, pane);
@@ -457,9 +465,7 @@ pub fn sayBack(p: *Pardes, id: usize) void {
// ---- the words ----
-/// `newest`: out of rest (UX D1), the owner's word and the newest back
-/// step's alone, each with the separator after it.
-pub const Part = enum { back, forward, newest };
+pub const Part = enum { back, forward };
/// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's
/// own text. A place's file is named by its basename, or where another
@@ -505,7 +511,7 @@ pub fn backs(t: *const Trail) usize {
/// The steps a part writes.
fn range(t: *const Trail, part: Part) [2]usize {
return switch (part) {
- .back, .newest => .{ 0, t.backs() },
+ .back => .{ 0, t.backs() },
.forward => .{ @min(t.n, t.cur + 1), t.n },
};
}
@@ -522,7 +528,6 @@ pub const shown_ahead = 2;
fn folds(t: *const Trail, part: Part, whole: usize, i: usize) bool {
const end = t.backs();
return switch (part) {
- .newest => false,
.forward => t.steps[i] == .place and i > t.cur + shown_ahead,
.back => i + whole < end and switch (t.steps[i]) {
.place => true,
@@ -541,42 +546,26 @@ fn runStart(t: *const Trail, part: Part, whole: usize, i: usize) usize {
return at;
}
-/// The cells of the newest step's word out of rest: a longer one is cut
-/// in its middle (UX D1: `Find pick…3/6`).
-const newest_cells = 24;
-
/// Step `i`'s word as `part` writes it, null where it writes none: a
-/// folded step's is the fold's `+N` on its first, none on the others; out
-/// of rest the owner's and the newest step's alone, a word longer than
-/// `newest_cells` keeping its first and last cells around a `…`.
-fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) ?[]const u8 {
- if (part == .newest and t.steps[i] != .owner and i + 1 != t.backs()) return null;
+/// folded step's is the fold's `+N` on its first, none on the others.
+fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + 16]u8) ?[]const u8 {
if (folds(t, part, whole, i)) {
if (runStart(t, part, whole, i) != i) return null;
var end = i;
while (end < range(t, part)[1] and folds(t, part, whole, end)) end += 1;
return std.fmt.bufPrint(buf, "+{d}", .{end - i}) catch unreachable; // a count fits
}
- const word = wordOf(t, i, buf);
- if (part != .newest or word.len <= newest_cells) return word;
- const tab = 8; // a step's word holds no tab
- if (panes.File.displayWidth(tab, word) <= newest_cells) return word;
- const head = panes.File.byteAtDisplay(tab, word, newest_cells / 2);
- var tail = word.len;
- while (tail > head and panes.File.displayWidth(tab, word[tail..]) < newest_cells / 2 - 1) tail = modal.prevGrapheme(word, tail);
- return std.fmt.bufPrint(cut, "{s}…{s}", .{ word[0..head], word[tail..] }) catch word;
+ return wordOf(t, i, buf);
}
/// The back steps' words, each with the separator after it (before the
/// path), or the forward steps', each with one before it (after the path),
-/// each run of folded ones as one `+N` (`folds`); out of rest (`newest`) the
-/// owner's and the newest's.
+/// each run of folded ones as one `+N` (`folds`).
pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void {
var buf: [max_text + 16]u8 = undefined;
- var cut: [max_text + 16]u8 = undefined;
const r = range(t, part);
- for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| switch (part) {
- .back, .newest => try w.print("{s}" ++ sep, .{word}),
+ for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf)) |word| switch (part) {
+ .back => try w.print("{s}" ++ sep, .{word}),
.forward => try w.print(sep ++ "{s}", .{word}),
};
}
@@ -584,10 +573,9 @@ pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.I
/// The bytes `write` writes for `part`.
pub fn bytes(t: *const Trail, part: Part, whole: usize) usize {
var buf: [max_text + 16]u8 = undefined;
- var cut: [max_text + 16]u8 = undefined;
var n: usize = 0;
const r = range(t, part);
- for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| {
+ for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf)) |word| {
n += word.len + sep.len;
};
return n;
@@ -604,9 +592,8 @@ pub fn walked(t: *const Trail) ?u8 {
return null;
}
-/// Whether pane `pane`'s tag is out of rest in the live view (UX D1: its
-/// path, its forward steps and its own words hidden, the owner and the
-/// newest step before the head). Asking is rest.
+/// Whether pane `pane`'s tag is out of rest in the live view: its head and
+/// band hang under it, over its body (UX DESIGN I1, M2). Asking is rest.
pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool {
const host = TagState.hostOf(p) orelse return false;
return p.panes[host] == pane;
@@ -616,13 +603,12 @@ pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool {
/// what `write` writes for the back steps, the newest `whole` whole.
pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize {
var buf: [max_text + 16]u8 = undefined;
- var cut: [max_text + 16]u8 = undefined;
const at = if (folds(t, .back, whole, i)) runStart(t, .back, whole, i) else i;
var x: usize = 0;
- for (0..at) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| {
+ for (0..at) |j| if (wordIn(t, .back, whole, j, &buf)) |word| {
x += word.len + sep.len;
};
- const word: []const u8 = wordIn(t, .back, whole, at, &buf, &cut) orelse "";
+ const word: []const u8 = wordIn(t, .back, whole, at, &buf) orelse "";
return .{ x, x + word.len };
}
@@ -635,11 +621,10 @@ pub fn isFolded(t: *const Trail, i: usize, whole: usize) bool {
/// for it, null on a separator or past them.
pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 {
var buf: [max_text + 16]u8 = undefined;
- var cut: [max_text + 16]u8 = undefined;
var x: usize = 0;
const r = range(t, part);
for (r[0]..r[1]) |i| {
- const word = wordIn(t, part, whole, i, &buf, &cut) orelse continue;
+ const word = wordIn(t, part, whole, i, &buf) orelse continue;
if (part == .forward) x += sep.len;
// A fold's `+N` is the step nearest the path of those it holds.
if (off >= x and off < x + word.len) {
@@ -969,10 +954,12 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC
f.look(f.held, "rank.zig", 12);
const r = p.view().active;
// A list asked from the held pane (SPC e's places, a server's answer):
- // its Enter lands in the reader, nothing made.
+ // hung under the held pane's tag (UX DESIGN O1), its Enter lands in the
+ // reader, nothing made.
const rows = try std.fmt.bufPrint(&buf, "{s}/place.zig:8:1 of\n{s}/place.zig:40:1 Span\n", .{ f.dir, f.dir });
pardes.Pick.open(p, f.held, .list, "Refs", "", rows);
- try std.testing.expectEqual(p.panes[r].?.serial, p.view().tag_state.host);
+ try std.testing.expectEqual(owner, p.view().tag_state.host);
+ try std.testing.expectEqual(p.panes[r].?.serial, pardes.Pick.live(p).?.landing);
pardes.Pick.landHere(p);
p.sync();
// The reader stepped (to another file: a pane of its own, its owner's
@@ -1180,7 +1167,7 @@ test "a band on a walked reading pane is whole: the layout's floor counts its ta
try std.testing.expect(at.band > 0);
try std.testing.expectEqual(pardes.Band.takes(p, r), at.band);
try std.testing.expectEqual(layout.wantedTagRows(p, r), pane.tag_rows);
- try std.testing.expect(v.rects[r].h >= @max(pane.tag_rows, at.text + at.band));
+ try std.testing.expect(v.rects[r].h >= at.tag + at.over);
p.update(.{ .key = .{ .cp = pardes.Key.escape } });
p.sync();
try std.testing.expect(pardes.TagState.hostOf(p) == null);
@@ -1301,7 +1288,7 @@ test "Jumps new-pane jumps as before the walk: a new pane for a file no pane sho
try std.testing.expectEqual(open + 2, now);
}
-test "Enter on a word of the walk, the keyboard in the tag, goes back to its step as a click does; out of rest the walk folds to its newest word" {
+test "Enter on a word of the walk, the keyboard in the tag, goes back to its step as a click does; out of rest the walk is as at rest, its words its steps (UX DESIGN M1)" {
var f: Fixture = .{ .p = undefined, .tmp = undefined };
try f.init(60);
defer f.deinit();
@@ -1314,35 +1301,33 @@ test "Enter on a word of the walk, the keyboard in the tag, goes back to its ste
var at: [64]u8 = undefined;
const rest = try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:10 › rank.zig:20 › {s}/rank.zig Keep", .{ owner, f.dir });
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest));
- // SPC, its level shown: out of rest the tag is the owner, the newest
- // step and the head (UX D1): no older step, no path, no Keep, none of
- // its own words; back at rest, as they were.
+ // SPC, its level shown: out of rest the tag is as at rest, every step,
+ // the path and Keep, the head under it (UX DESIGN M1); each word its
+ // step.
const whole_rest = try p.gpa.dupe(u8, try tagOf(p, pane));
defer p.gpa.free(whole_rest);
p.update(.{ .key = .{ .cp = ' ' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
p.sync();
- var folded_buf: [4096 + 128]u8 = undefined;
+ try std.testing.expect(pardes.TagState.hostOf(p) == r);
const out = try tagOf(p, pane);
- try std.testing.expect(std.mem.startsWith(u8, out, try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:20 › ␣ ▸ ", .{owner})));
- try std.testing.expect(std.mem.indexOf(u8, out, "rank.zig:10") == null and std.mem.indexOf(u8, out, f.dir) == null and std.mem.indexOf(u8, out, "Keep") == null);
- // Look on the newest step's word is that step.
+ try std.testing.expectEqualStrings(whole_rest, out);
try std.testing.expectEqual(@as(?u8, pane.trail.cur - 1), pardes.tagline.trailAt(p, pane, std.mem.indexOf(u8, out, "rank.zig:20").? + 3));
try std.testing.expectEqual(@as(?u8, 0), pardes.tagline.trailAt(p, pane, 1));
p.update(.{ .key = .{ .cp = pardes.Key.escape } });
try std.testing.expectEqualStrings(whole_rest, try tagOf(p, pane));
- // Back a step (a forward step after the path at rest): out of rest the
- // forward step is hidden as the path is.
+ // Back a step: the forward step after the path, out of rest as at rest.
pardes.Trail.lookStep(p, r, pane.trail.cur - 1);
p.sync();
- try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") != null);
+ const back = try p.gpa.dupe(u8, try tagOf(p, pane));
+ defer p.gpa.free(back);
+ try std.testing.expect(std.mem.indexOf(u8, back, "rank.zig:30") != null);
p.update(.{ .key = .{ .cp = ' ' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
p.sync();
- try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:10 › ␣ ▸ ", .{owner})));
- try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") == null);
+ try std.testing.expectEqualStrings(back, try tagOf(p, pane));
p.update(.{ .key = .{ .cp = pardes.Key.escape } });
pardes.Trail.lookStep(p, r, pane.trail.cur + 1);
p.sync();
diff --git a/core/bindings.zig b/core/bindings.zig
index da8ed4dc..6128e311 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -596,7 +596,9 @@ test "\" shows the registers rolled, the ones holding something, each its value
p.advance(p.clock.now_ns);
try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
- const rolled = try tagline.tagText(p, a, pane);
+ // Rolled under the tag, which is as it was (UX DESIGN M1).
+ try std.testing.expectEqualStrings(rest, try tagline.tagText(p, a, pane));
+ const rolled = (try @import("TagState.zig").head(p, a, pane)).?.text;
try std.testing.expect(std.mem.indexOf(u8, rolled, "\" ▸ \" self.dirty = true; a const best = rank(q… n ab⏎ p …proj/core/Query.zig % /test.txt . o # 1 ") != null);
// Its ⏎ in the dim ink.
const h = (try @import("TagState.zig").head(p, a, pane)).?;
@@ -653,13 +655,13 @@ test "\" shows the registers rolled, the ones holding something, each its value
try std.testing.expect(std.mem.indexOf(u8, band.items, "return best;") != null);
// Enter chooses it: its verbs, rolled.
p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after P before R replace y into") != null);
+ try std.testing.expect(std.mem.indexOf(u8, (try @import("TagState.zig").head(p, a, pane)).?.text, "\" a ▸ p after P before R replace y into") != null);
try std.testing.expect(!p.view().tag_state.unrolled);
// Backspace: the registers again; a register's own key goes down too.
p.update(.{ .key = .{ .cp = Key.backspace } });
- try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" ▸ \" self.dirty") != null);
+ try std.testing.expect(std.mem.indexOf(u8, (try @import("TagState.zig").head(p, a, pane)).?.text, "\" ▸ \" self.dirty") != null);
p.update(.{ .key = .{ .cp = 'a' } });
- try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after") != null);
+ try std.testing.expect(std.mem.indexOf(u8, (try @import("TagState.zig").head(p, a, pane)).?.text, "\" a ▸ p after") != null);
// p pastes it after the selection, and the tag is at rest.
p.update(.{ .key = .{ .cp = 'p' } });
try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "const best = rank(q, name) orelse continue;") != null);
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 7da2129d..46a98760 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -1493,7 +1493,9 @@ test "a selection that is the current place is drawn as the current place, its s
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
colors.setThemeIndex(p, colors.themeIndex("orchard").?);
- const pane = try p.setTestFile("alpha beta\ngamma alpha\nb\n");
+ // Its first line under the `/` field's row (UX DESIGN M2), the places
+ // on the lines after it.
+ const pane = try p.setTestFile("zero\nalpha beta\ngamma alpha\nb\n");
const c = p.chrome();
var frame: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer frame.deinit();
@@ -1510,7 +1512,7 @@ test "a selection that is the current place is drawn as the current place, its s
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
var s = try p.render(frame.allocator());
for (0..5) |i| {
- const cell = s.at(x + @as(u16, @intCast(i)), y).style;
+ const cell = s.at(x + @as(u16, @intCast(i)), y + 1).style;
try std.testing.expectEqual(Color{ .rgb = c.hit_current }, cell.bg);
try std.testing.expectEqual(Color{ .rgb = c.hit_current_text }, cell.fg);
}
@@ -1520,10 +1522,10 @@ test "a selection that is the current place is drawn as the current place, its s
keys(p, "n");
try std.testing.expectEqual(@as(?usize, 1), pane.places.current);
s = try p.render(frame.allocator());
- for (6..11) |i| try std.testing.expectEqual(Color{ .rgb = c.hit_current }, s.at(x + @as(u16, @intCast(i)), y + 1).style.bg);
- try std.testing.expect(s.cursor != null and s.cursor.?.y == y + 1 and s.cursor.?.x >= x + 6 and s.cursor.?.x <= x + 10);
+ for (6..11) |i| try std.testing.expectEqual(Color{ .rgb = c.hit_current }, s.at(x + @as(u16, @intCast(i)), y + 2).style.bg);
+ try std.testing.expect(s.cursor != null and s.cursor.?.y == y + 2 and s.cursor.?.x >= x + 6 and s.cursor.?.x <= x + 10);
// The line selected, past the place: a selection again.
keys(p, "x");
s = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = c.page.selection.ground }, s.at(x + 6, y + 1).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = c.page.selection.ground }, s.at(x + 6, y + 2).style.bg);
}
diff --git a/core/draw.zig b/core/draw.zig
index 0946978f..648808aa 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -344,15 +344,15 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
s.body_layers[id].rows = 0;
try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active);
}
- // A tag out of rest after every body (UX DESIGN I1): its head and its
- // band past its own rows are drawn over the top rows of its body,
- // which stay where they were; beside them the grip's column on the
- // tag's ground, and a caret under them hidden until rest.
+ // A tag out of rest after every body (UX DESIGN I1, M2): drawn as at
+ // rest, its head and band hanging under it over the top rows of its
+ // body, which stay where they were; beside them the grip's column on
+ // the tag's ground, and a caret under them hidden until rest.
if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (v.rects[id].w > config.GUTTER and v.rects[id].h > 0) {
const r = v.rects[id];
const at = pardes.Band.covered(p, pane, id);
- const y = p.tagTop(pane, r) + pane.tag_rows;
- const rows = @min(at.over, r.h -| pane.tag_rows);
+ const y = p.tagTop(pane, r) + at.tag;
+ const rows = @min(at.over, r.h -| at.tag);
if (rows > 0) {
s.fill(r.x, y, config.GUTTER, rows, .{ .bg = .{ .rgb = chrome.on(if (id == v.active) .focus else .plain).ground }, .font_role = .tagline });
if (s.cursor) |c| if (c.x >= r.x and c.x < r.x + r.w and c.y >= y and c.y < y + rows) {
@@ -362,8 +362,8 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
s.body_layers[id].cursor = null;
};
}
- try joinPaneTag(p, s, arena, pane, r, id, id == v.active, at.text);
- if (at.band > 0) try joinBand(p, s, arena, pane, r, id, id == v.active, at);
+ try joinPaneTag(p, s, arena, pane, r, id, id == v.active, at.tag);
+ if (at.over > 0) try joinBand(p, s, arena, pane, r, id, id == v.active, at);
};
// Each notice once, as a tag layer, and the grid's chip a copy of it.
for (s.regionList()) |region| {
@@ -500,8 +500,9 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// In window mode the box holds the pane's letter instead of its mode.
const label: ?u8 = if (p.view().window_pick != null) layout.windowLabel(p, id) else null;
// A tag in a typing state is typed in: its box says so (walk UI SPEC
- // §3.2), whatever the body's mode.
- const typing = p.view().tag_state.kind != .rest and TagState.hostOf(p) == id;
+ // §3.2), whatever the body's mode; not while it waits for the keyboard
+ // (UX DESIGN O2).
+ const typing = p.view().tag_state.kind != .rest and !p.view().tag_state.waits and TagState.hostOf(p) == id;
s.set(r.x, tag_y, if (label) |*letter| @as(*const [1]u8, letter) else if (typing) config.tag_insert else switch (pane.body.mode) {
.normal => config.tag_normal,
.insert => config.tag_insert,
@@ -717,8 +718,6 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u
}
fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } {
- // Out of rest no name is shown (UX D1).
- if (pardes.Trail.outOfRest(p, pane)) return null;
if (pane.isTerminal()) {
// `tag` is the first row; a prefix longer than it ran to a second.
var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n");
@@ -730,7 +729,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len
return null;
}
var start: usize = tagline.nameAt(p, pane);
- const name = if (pane.file) |file|
+ const name = if (tagline.named(p, pane)) |file|
if (pane.prompt == .name) pane.input.own orelse file.path else file.path
else if (pane.addon) |k| blk: {
// A kind's tag may put its words before the path (an image's
@@ -850,9 +849,8 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
}
/// A pane's tag's `rows` text rows (MAX_TAG_ROWS at most; out of rest its
-/// head's, Band.covered, past its own rows over its body), painted once
-/// into their layer, a row to a line, and copied into the grid; the grid's
-/// caret where the layer has it.
+/// rows at rest, Band.covered), painted once into their layer, a row to a
+/// line, and copied into the grid; the grid's caret where the layer has it.
fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void {
const v = p.view();
const capacity = layout.tagCapacity(p, r.w -| TAG_TEXT_INSET);
@@ -909,19 +907,21 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
}
}
-/// The band under pane `id`'s tag text (Band.zig), its `drawn.band` rows
-/// under the head's `drawn.text`, painted once into its layer at the
-/// tagline's pitch, a row to a line, and copied into the grid: the spines
-/// and steps in the tag's tint, the keys in the key ink, the cursor's row
-/// tinted as a selection.
+/// The head and the band under pane `id`'s tag (UX DESIGN M2): the head's
+/// `drawn.head` rows (TagState.head: its keys, the level or the field and
+/// its caret, the count, the hints), then the band's `drawn.band`
+/// (Band.zig), painted once into their layer at the tagline's pitch, a row
+/// to a line, and copied into the grid: the spines and steps in the tag's
+/// tint, the keys in the key ink, the cursor's row tinted as a selection.
fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, drawn: pardes.Band.Covered) !void {
const layer = &s.tag_layers[pardes.BAND_LAYER];
- const rows = drawn.band;
+ const rows = drawn.over;
if (r.w <= TAG_TEXT_INSET) return;
- const band = (try pardes.Band.of(p, arena, pane, id)) orelse return;
+ const head = (try TagState.head(p, arena, pane)) orelse return;
+ const band = try pardes.Band.of(p, arena, pane, id);
const chrome = p.chrome();
const tab = p.settings.tab;
- const columns = @max(band.columns, 1);
+ const columns = @max(layout.tagCapacity(p, r.w -| TAG_TEXT_INSET), 1);
// The inks of its tag's ground, focused or not, whatever its mode
// (DESIGN.md B6, G1'), and of its cursor row's selection, a ground of
// its own (B1.3).
@@ -933,10 +933,45 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@memset(storage, .{});
var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab };
- for (0..rows) |y| {
- const row: u16 = @intCast(y);
- t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
- const ln = try band.line(arena, tab, row);
+ t.fill(0, 0, columns, rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
+ // The head's rows, as it laid itself out at the tag's width (UX D2, D3).
+ const shown = try tagline.wrapTag(tab, arena, head.text, columns);
+ var lines: [MAX_TAG_ROWS][]const u8 = @splat("");
+ var split = std.mem.splitScalar(u8, shown.text, '\n');
+ for (lines[0..drawn.head], 0..) |*line, y| {
+ line.* = split.next() orelse break;
+ _ = t.print(0, @intCast(y), columns, line.*, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
+ }
+ // Its keys in the key ink, its dimmed, underlined and struck words
+ // (TagState.Span), over whichever rows they wrapped onto.
+ for (head.spans) |span| {
+ const a = modal.positionAt(shown.text, shown.fromReal(span.lo));
+ const b = modal.positionAt(shown.text, shown.fromReal(span.hi));
+ var row = a.row;
+ while (row <= b.row and row < drawn.head) : (row += 1) {
+ const line = lines[row];
+ var col = panes.File.rawDisplayCol(tab, line, @min(if (row == a.row) a.col else 0, line.len));
+ const end = panes.File.rawDisplayCol(tab, line, @min(if (row == b.row) b.col else line.len, line.len));
+ while (col < end and col < columns) : (col += 1) {
+ const style = &t.at(@intCast(col), @intCast(row)).style;
+ switch (span.style) {
+ .key => {
+ style.fg = .{ .rgb = inks.key };
+ style.bold = true;
+ },
+ .dim => style.fg = .{ .rgb = inks.dim },
+ .under => style.ul = .single,
+ .strike => style.strikethrough = true,
+ .err => style.fg = .{ .rgb = inks.severity[0] },
+ .rule => style.fg = .{ .rgb = inks.rule },
+ }
+ }
+ }
+ }
+ // The band's rows under the head's.
+ if (band) |b| for (0..drawn.band) |y| {
+ const row: u16 = @intCast(drawn.head + y);
+ const ln = try b.line(arena, tab, @intCast(y));
_ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
// The spines and the rules between steps in the rule ink; a row's
// `▶` (the cursor) and `•` (marked) in the key ink.
@@ -964,20 +999,20 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
t.tint(part.col, row, end - part.col, selected.ground, selected.text);
}
var c = part.col;
- var b: usize = 0;
- while (b < part.row.text.len and c < end) : (c += 1) {
- const next = modal.nextGrapheme(part.row.text, b);
+ var i: usize = 0;
+ while (i < part.row.text.len and c < end) : (c += 1) {
+ const next = modal.nextGrapheme(part.row.text, i);
const style = &t.at(c, row).style;
- if (b < part.row.key) {
+ if (i < part.row.key) {
style.fg = .{ .rgb = key };
style.bold = true;
}
// A chord (Help's `SPC h t`): keys, at the text's weight.
- if (b < part.row.chord) style.fg = .{ .rgb = key };
- if (b < part.row.pre) style.fg = .{ .rgb = chrome.name[@intFromEnum(g)] };
- if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = dim };
- if (b < part.row.kind) style.fg = .{ .rgb = inks.kind };
- for (part.row.keys) |k| if (k == b) {
+ if (i < part.row.chord) style.fg = .{ .rgb = key };
+ if (i < part.row.pre) style.fg = .{ .rgb = chrome.name[@intFromEnum(g)] };
+ if (part.row.dim or (i >= part.row.pre and i < part.row.pre + part.row.faint) or (i >= part.row.quiet[0] and i < part.row.quiet[1])) style.fg = .{ .rgb = dim };
+ if (i < part.row.kind) style.fg = .{ .rgb = inks.kind };
+ for (part.row.keys) |k| if (k == i) {
style.fg = .{ .rgb = key };
style.bold = true;
};
@@ -985,11 +1020,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
// A matched letter: the match ink, bold, on the row's own
// ground (never a ground of its own: on the cursor row's
// selection one vanished).
- for (part.row.marks) |m| if (m == b) {
+ for (part.row.marks) |m| if (m == i) {
style.fg = .{ .rgb = if (part.row.on) selected.match else inks.match };
style.bold = true;
};
- b = next;
+ i = next;
}
// Its meta, right-aligned in the part (Band.line), dim.
if (pardes.Band.metaShown(tab, part.row, part.width) and part.col + part.width <= columns) {
@@ -997,12 +1032,12 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = dim };
}
}
- }
+ };
const count = @as(usize, columns) * rows;
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
@memcpy(layer.cells, storage);
- // Under the head's rows, over the body's top ones (Band.covered).
- const y0 = p.tagTop(pane, r) + drawn.text;
+ // Under the tag's rows, over the body's top ones (Band.covered).
+ const y0 = p.tagTop(pane, r) + drawn.tag;
layer.kind = .band;
layer.id = @intCast(id);
layer.serial = pane.serial;
@@ -1013,6 +1048,18 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
layer.bg = bg;
layer.cursor = null;
for (0..rows) |y| joinCells(s, r.x + TAG_TEXT_INSET, y0 + @as(u16, @intCast(y)), storage[y * columns ..][0..columns], 0, r.w - TAG_TEXT_INSET, .{ .rgb = fg });
+ // A head typed in: its caret a bar at the field's, the keyboard's
+ // where the pane has it.
+ if (head.caret) |c| if (active and !p.view().tag_state.waits) {
+ const at = modal.positionAt(shown.text, shown.fromReal(c));
+ if (at.row < drawn.head) {
+ const col = panes.File.rawDisplayCol(tab, lines[at.row], @min(at.col, lines[at.row].len));
+ if (col < columns) {
+ layer.cursor = .{ .x = @intCast(col), .y = @intCast(at.row), .bar = true };
+ if (col < r.w - TAG_TEXT_INSET) s.cursor = .{ .x = r.x + TAG_TEXT_INSET + @as(u16, @intCast(col)), .y = y0 + @as(u16, @intCast(at.row)), .bar = true };
+ }
+ }
+ };
}
/// Bytes `lo` to `hi` of a tag's text in `ink`, over whichever of its
@@ -1058,9 +1105,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
.font_role = .tagline,
});
const whole = try tagline.tagText(p, arena, pane);
- // Out of rest, the head in place of the tag's own text (TagState).
- const head = try TagState.head(p, arena, pane);
- const tail = if (head) |h| h.text else tagline.curTail(pane);
+ // A question in place of the tag's own text (TagState.asking).
+ const question = try TagState.asking(p, arena, pane);
+ const tail = if (question) |h| h.text else tagline.curTail(pane);
const prefix_len = whole.len - tail.len;
// A row per line shown, from `tag_top`: the tag's first line carries
// the prefix, the rest are the tag's own text alone.
@@ -1083,7 +1130,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col)))));
if (at.row < top or at.row >= top + rows) break :caret null;
break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) };
- } else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: {
+ } else if (pane.focus == .tag and pane.prompt == .none and question == null) caret: {
const real = modal.offsetAt(whole, .{ .row = @intCast(@max(0, pane.tag.cur_row)), .col = @intCast(@max(0, pane.tag.cur_col)) });
const at = modal.positionAt(shown.text, shown.fromReal(real));
if (at.row < top or at.row >= top + rows) break :caret null;
@@ -1098,9 +1145,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
_ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style);
}
// The pane's progress at its first row's right end, where the row has
- // room for it (SPEC §10.2); out of rest the head's right block is
- // there (UX D1).
- if (top == 0 and rows > 0 and !pardes.Trail.outOfRest(p, pane)) for (p.messages.live[0..p.messages.live_len]) |*said| {
+ // room for it (SPEC §10.2).
+ if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
if (said.kind != .progress or said.pane != pane.serial) continue;
var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined;
const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break;
@@ -1113,8 +1159,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// wrapped onto.
const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len];
// Its computed words (UX K'1), between its path and the user's text,
- // at rest and not asking: the words' ink, quieter than the full one.
- if (head == null and !TagState.asks(p, pane)) {
+ // not asking: the words' ink, quieter than the full one.
+ if (question == null) {
const words = tagline.computedWords(pane);
const end = prefix_len -| 1;
inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, end -| words.len, @min(end, first_line.len), inks.word, false);
@@ -1134,7 +1180,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// `+N` too; the word n walks underlined in the key ink (UX D8).
const ahead = tagline.forwardSpan(p, pane);
if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), inks.dim, false);
- if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) {
+ if (pane.file != null and pane.trail.n > 0) {
const kept = tagline.folded(p, pane).whole;
const t = &pane.trail;
// Each run of folded places' `+N` (UX L'1: words never fold).
@@ -1149,9 +1195,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
}
// A search word its places no longer light, dimmed (Prompt.zig).
if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), inks.dim, false);
- // The head's keys in the key ink, its dimmed, underlined and struck
- // words (TagState.Span), over whichever rows they wrapped onto.
- if (head) |h| for (h.spans) |span| {
+ // A question's keys in the key ink, its dimmed words (TagState.Span),
+ // over whichever rows they wrapped onto.
+ if (question) |h| for (h.spans) |span| {
const a = modal.positionAt(shown.text, shown.fromReal(prefix_len + span.lo));
const b = modal.positionAt(shown.text, shown.fromReal(prefix_len + span.hi));
var row = @max(a.row, top);
@@ -1180,7 +1226,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
};
// The tag's own selections, while it has the keyboard, a line at a
// time. A range of one grapheme is the block cursor, not a selection.
- if (pane.focus == .tag and head == null) {
+ if (pane.focus == .tag and question == null) {
var ranges: [Text.max_selections]modal.Selection = undefined;
const got = pane.tag.ranges(whole, 0, &ranges);
for (ranges[0..got.n]) |range| {
@@ -1200,15 +1246,6 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
}
}
}
- // A head typed in: its caret a bar at the field's.
- if (head) |h| if (h.caret) |c| if (active) {
- const at = modal.positionAt(shown.text, shown.fromReal(prefix_len + c));
- if (at.row >= top and at.row < top + rows) {
- const line = lines[at.row - top];
- const col = panes.File.rawDisplayCol(p.settings.tab, line, @min(at.col, line.len));
- if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y + @as(u16, @intCast(at.row - top)), .bar = true };
- }
- };
// the caret: bar while typing, block in normal mode (same rule as a body)
if (caret) |at| {
const col = panes.File.rawDisplayCol(p.settings.tab, lines[at.row], at.at) -| pane.tag_scroll;
@@ -1851,7 +1888,7 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d
defer frame.deinit();
const a = frame.allocator();
const inks = p.chrome().on(.focus);
- // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`.
+ // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ? help`.
p.clock.now_ns = 5 * std.time.ns_per_s;
p.clock.stepped_ns = p.clock.now_ns;
p.update(.{ .key = .{ .cp = ' ' } });
@@ -1860,7 +1897,8 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d
p.sync();
const s = try p.render(a);
const r = p.view().rects[p.view().active];
- const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * pardes.Band.covered(p, pane, p.view().active).text];
+ const drawn = pardes.Band.covered(p, pane, p.view().active);
+ const row = s.cells[@as(usize, r.y + drawn.tag) * s.cols ..][0 .. @as(usize, s.cols) * drawn.head];
const Row = struct {
fn find(cells: []const Cell, word: []const u8) ?usize {
var at: usize = 0;
@@ -1872,7 +1910,7 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d
return null;
}
};
- const hint = Row.find(row, "unroll").?;
+ const hint = Row.find(row, "? help").?;
try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg);
for (row) |cell| try std.testing.expect(!cell.style.dim);
var keys: usize = 0;
diff --git a/core/edit.zig b/core/edit.zig
index 12cd7706..622699f6 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -688,8 +688,8 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa
// back, as a body's is kept.
defer retireEditText(e, new);
const pane = t.pane() orelse return;
- // Out of rest the tag shows its head, which is no one's to edit.
- if (try pardes.TagState.head(e.p, e.scratch, pane) != null) {
+ // A question shown in the tag is no one's to edit.
+ if (pardes.TagState.asks(e.p, pane)) {
t.refused = true;
return;
}
diff --git a/core/exec.zig b/core/exec.zig
index 47fea012..c1e68970 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -983,6 +983,13 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
var said: pardes.Kind.Buf(96) = .{};
return p.reportFailure(id, said.print("{s} is GUI-only, invalid here", .{@tagName(b)}));
}
+ // A word that changes or closes the pane a picker asks from or
+ // previews in ends the picker first, as Esc does (UX DESIGN O3); then
+ // it runs as at rest (on nothing, the pane made for the picker gone).
+ switch (b) {
+ .Get, .Undo, .Redo, .Save, .Del, .Keep => pardes.Pick.yieldFor(p, id),
+ else => {},
+ }
// No pane at all (the window Delcol emptied): a word runs all the same,
// with a stand-in that is no pane (New, Newcol, Exit are what make sense).
const pane = p.panes[id] orelse (if (builtins.registry.scope(b) == .session or panes.anyPane(p) == null) panes.standIn(p) orelse return else return);
diff --git a/core/keys.zig b/core/keys.zig
index 05349d59..61ebaab9 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -197,6 +197,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// A root this key strikes starts its which-key delay; one it ends
// takes its level away (TagState).
defer TagState.follow(p);
+ // A key that moves the keyboard to the pane a waiting state hangs
+ // under (`C-w`'s pick, `SPC w k`) gives the state the keyboard back (UX
+ // DESIGN O2).
+ const keyboard = p.view().active;
+ defer if (p.view().tag_state.waits and p.view().window_pick == null and p.view().active != keyboard and TagState.hostOf(p) == p.view().active) {
+ p.view().tag_state.waits = false;
+ };
// A double-click is two clicks with nothing between them.
p.view().last_click = null;
if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err);
@@ -229,8 +236,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
return;
}
p.view().answering = 0;
- // A tag in a typing state takes every key (TagState: Help, describe-key).
- if (p.view().tag_state.kind != .rest) return tagStateKey(p, key);
+ // A tag in a typing state takes every key (TagState: Help, describe-key);
+ // one waiting for the keyboard (UX DESIGN O2) only Esc, which ends it
+ // first: the others go where the keyboard is.
+ if (p.view().tag_state.kind != .rest) {
+ if (!p.view().tag_state.waits) return tagStateKey(p, key);
+ if (hit(key, config.escape)) return TagState.toRest(p);
+ }
Prompt.keyAtRest(p, key);
@import("Pick.zig").keyAtRest(p, key);
// Esc takes a hover's ghost lines away (SPEC §3.5) before anything else
diff --git a/core/layout.zig b/core/layout.zig
index c8fb91f9..b15c7200 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -592,7 +592,7 @@ pub const min_body_rows = 2;
/// wants a row more.
pub fn wantedTagRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return BOX_H;
- return tagRows(p, id, tagline.computedWords(pane));
+ return tagRows(p, id, tagline.tagWords(p, pane));
}
/// The rows pane `id`'s tag at rest takes with computed words `words`.
@@ -609,20 +609,19 @@ fn tagRows(p: *Pardes, id: usize, words: []const u8) u16 {
return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS)));
}
-/// The rows pane `id`'s tag's text takes now: out of rest its head
-/// (TagState) after what of its prefix stays (UX D1), wrapped at its width
-/// as Pardes.sync wraps it; at rest what wantedTagRows says.
+/// The rows pane `id`'s head takes under its tag out of rest (TagState,
+/// UX DESIGN M2), wrapped at the tag's width as the band draws it; none at
+/// rest.
pub fn headRows(p: *Pardes, id: usize) u16 {
- const pane = p.panes[id] orelse return BOX_H;
- if (pane.collapsed or !pane.tag_expanded) return BOX_H;
+ const pane = p.panes[id] orelse return 0;
+ if (pane.collapsed) return 0;
var wrap_room: [Pane.prefix_room]u8 = undefined;
var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
const wa = wrap_fba.allocator();
- const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows;
- const tail = tagline.shownTail(p, wa, pane) catch return pane.tag_rows;
- const whole = std.mem.concat(wa, u8, &.{ prefix, tail }) catch return pane.tag_rows;
- const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows;
- return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS)));
+ // A head with no room to be made in is a row still.
+ const head = (pardes.TagState.head(p, wa, pane) catch return 1) orelse return 0;
+ const shown = tagline.wrapTag(p.settings.tab, wa, head.text, tagline.tagWidth(p, id)) catch return 1;
+ return @intCast(@min(shown.rows(), MAX_TAG_ROWS));
}
/// The rows a placement, and a `size`, leave a pane: its tag at its width
@@ -1608,23 +1607,25 @@ pub fn compute(p: *Pardes) void {
/// The fewest rows a pane is laid out with: a terminal keeps its tag and
/// `min_body_rows` (a shorter one loses its prompt and reads busy for
/// ever), a text pane may shrink to its tag, as acme's windows do. A tag
-/// out of rest has the rows for its head and its band, drawn over its body
-/// (UX DESIGN I1); a picker's (code actions' too: its body is the preview)
-/// a body of 60 % of the pane and 6 rows at least under them (UX D6). Those
-/// are borrowed from the column's other panes, which shrink to their tags
-/// until it rolls up (walk UI SPEC §3.6). A terminal's and a kind's size
-/// is their user's: a transient state never resizes the pty under a
-/// program or a kind's view (a PDF's), it is drawn over as much of them as
-/// it has (R3).
+/// out of rest has the rows for its head and its band under it, drawn over
+/// its body (UX DESIGN I1, M4). The pane a picker's preview shows in (code
+/// actions' asking pane too: its body is the preview) has a body of 60 % of
+/// the pane and 6 rows at least under its tag, and its head and band when
+/// it asked (UX D6, DESIGN O1). Those are borrowed from the column's other
+/// panes, which shrink to their tags until it rolls up (walk UI SPEC
+/// §3.6). A terminal's and a kind's size is their user's: a transient
+/// state never resizes the pty under a program or a kind's view (a PDF's),
+/// it is drawn over as much of them as it has (R3).
fn floorRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return 0;
- const band = if (pane.isTerminal() or pane.addon != null) 0 else pardes.Band.takes(p, id);
- if (band > 0) {
+ const under = if (pane.isTerminal() or pane.addon != null) 0 else headRows(p, id) + pardes.Band.takes(p, id);
+ const preview = pardes.Pick.previewPane(p, id);
+ if (under > 0 or preview) {
// Worked out from the state, never the last sync's rows (the first
// layout after a head changed read the rows of the one before, and
// the next moved the body).
- const above = @max(wantedTagRows(p, id), headRows(p, id) + band);
- if (p.view().tag_state.kind != .pick) return above;
+ const above = wantedTagRows(p, id) + under;
+ if (!preview) return above;
// A body of 60 % is one and a half times what is above it.
return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2);
}
diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig
index c60eb72b..2f92f4dd 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -792,14 +792,14 @@ test "SPC l r types the new name in the pane's own tag, the body showing each pl
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
- try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), "Rename best → bester") != null);
+ try std.testing.expect(std.mem.indexOf(u8, (try pardes.TagState.head(p, a, pane)).?.text, "Rename best → bester") != null);
p.sync();
const sf = try p.render(a);
const body = sf.region(.body, id).?.rect;
var buf: [256]u8 = undefined;
// Each `best` in view struck and followed by the new name; `bestow` is
- // another word.
- try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y, &buf), "const bestbester = 1;") != null);
+ // another word. The first line is under the head's row (UX DESIGN M2).
+ try std.testing.expect(std.mem.indexOf(u8, rowText(sf, 0, body.y, &buf), "Rename best → bester") != null);
try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 1, &buf), "const b = bestbester + bestbester;") != null);
try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 2, &buf), "const bestow = 2;") != null);
try std.testing.expectEqualStrings("const best = 1;\nconst b = best + best;\nconst bestow = 2;\n", pane.file.?.content);
diff --git a/core/mouse.zig b/core/mouse.zig
index 04bbaeb4..dc730923 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -503,16 +503,22 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
pub fn handleMouse(p: *Pardes, event: Mouse) void {
const v = p.view();
- // A click that gives the keyboard to another pane ends the level or
- // typing state of the tag out of rest as Esc does, its text's prefix
- // with it (SPEC §3.4.6: only the pane with the keyboard leaves rest);
- // one in its band or its own tag keeps it.
+ // The mouse never ends a state as a side effect (UX DESIGN O2): an
+ // event that gives the keyboard to another pane leaves a state with a
+ // field (Help, a picker, a text prompt, `:`, rename) up, waiting for it
+ // (TagState.waits); a level, the registers or describe-key, which hold
+ // no typed text, end as Esc ends them, the text's prefix with them
+ // (SPEC §3.4.6). The pointer's motion and the wheel move no keyboard.
const host = pardes.TagState.hostOf(p);
defer if (host) |was| if (v.active != was) {
- const to = v.active;
- v.active = was;
- pardes.TagState.toRest(p);
- v.active = to;
+ if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) {
+ v.tag_state.waits = true;
+ } else {
+ const to = v.active;
+ v.active = was;
+ pardes.TagState.toRest(p);
+ v.active = to;
+ }
};
var m = event;
// A click goes somewhere else: the question it leaves unanswered is
@@ -611,6 +617,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
return;
}
+ // B1 off the head and the band gives the keyboard where it gives it at
+ // rest (a tag's text, a body, a header): a state with a field waits for
+ // it; a level, the registers and describe-key end first (UX DESIGN O2).
+ // B1 on them gives it back (bandPress).
+ if (m.kind == .press and m.button == config.select_button and host != null and bandPoint(p, mcol, mrow) == null) {
+ if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) v.tag_state.waits = true else pardes.TagState.toRest(p);
+ }
const hovered = paneAt(p, mcol, mrow);
// any press that is NOT the execute+select chord abandons a pending
@@ -726,7 +739,14 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
if (m.kind == .press) {
tagline.exitHeader(p);
}
- if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point);
+ if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m, point);
+ // B2 or B3 on the text a picker previews lands it first, as Enter
+ // does: acting on that file is taking it (UX DESIGN O3); the press then
+ // does what it does at rest, in the file landed.
+ if (m.kind == .press and (m.button == config.exec_button or m.button == config.look_button)) if (hovered) |id| if (pardes.Pick.previewsAt(p, id, mrow)) {
+ pardes.Pick.landHere(p);
+ p.layOut();
+ };
switch (m.button) {
.none, .back, .forward => {}, // hover and navigation handled above
@@ -920,77 +940,100 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
-/// A band's row, or a head's row past its tag's own (`head`), drawn over
-/// the body: a covered row belongs to the band, never to the body under it
-/// (UX DESIGN I1).
+/// A head's row (`head`) or a band's under it, drawn over the body: a
+/// covered row belongs to them, never to the body under it (UX DESIGN I1,
+/// M2).
const BandPoint = struct { id: usize, line: u16, col: u16, head: bool = false };
-/// The band row and column (at the tagline's pitch) a press is on, or the
-/// head's row over the body: a window's layer hit, or a grid cell under a
-/// tag's own rows.
+/// The head's or the band's row and column (at the tagline's pitch) a
+/// press is on: a window's layer hit, or a grid cell under a tag.
fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
const v = p.view();
if (v.pointer_tag_hit) |hit| {
- if (hit.kind == .band) return .{ .id = hit.id, .line = hit.line, .col = hit.col };
- const pane = (if (hit.kind == .pane and hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
- return if (hit.line >= pane.tag_rows) .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true } else null;
+ if (hit.kind != .band) return null;
+ const pane = (if (hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
+ const head = pardes.Band.covered(p, pane, hit.id).head;
+ if (hit.line < head) return .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true };
+ return .{ .id = hit.id, .line = hit.line - head, .col = hit.col };
}
const id = paneAt(p, mcol, mrow) orelse return null;
const pane = p.panes[id].?;
const at = pardes.Band.covered(p, pane, id);
const r = v.rects[id];
- const top = p.tagTop(pane, r);
- if (mrow < top + @min(pane.tag_rows, at.text) or mrow >= top + at.text + at.band or mcol < r.x + TAG_TEXT_INSET) return null;
+ const top = p.tagTop(pane, r) + at.tag;
+ if (mrow < top or mrow >= top + at.over or mcol < r.x + TAG_TEXT_INSET) return null;
const col = mcol - (r.x + TAG_TEXT_INSET);
- if (mrow < top + at.text) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
- return .{ .id = id, .line = mrow - top - at.text, .col = col };
+ if (mrow < top + at.head) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
+ return .{ .id = id, .line = mrow - top - at.head, .col = col };
}
-/// A press on a band (Band.zig), read-only text: the select button puts
-/// the rows' cursor on the row it is on; execute runs the word under it
-/// and look looks at it, as on a tag, the tag back at rest first.
-fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
+/// A press on a band (Band.zig), read-only text, and the wheel over it
+/// (UX DESIGN O2). The select button gives a state waiting for the
+/// keyboard its keyboard back (TagState.waits), puts the field's caret
+/// where it is in the head's field, and the rows' cursor on the row it is
+/// on. Execute runs the word under it and look looks at it, as on a tag: a
+/// level back at rest first, a state with a field kept up (what the word
+/// does may end it: Pick.yieldFor); B3 on a picker's row is Enter there,
+/// Shift-B3 S-Enter. The wheel moves a picker's cursor or Help's.
+fn bandPress(p: *Pardes, m: Mouse, point: BandPoint) void {
const v = p.view();
const arena = p.scratch.allocator();
- // A head's row over the body: its words as the tag's first row's.
+ const s = &v.tag_state;
+ const field = s.kind != .rest and s.kind != .describe;
+ if (m.button == .wheel_up or m.button == .wheel_down) {
+ const delta = if (m.button == .wheel_up) -config.wheel_rows else config.wheel_rows;
+ if (s.kind == .pick) pardes.Pick.wheel(p, delta);
+ if (s.kind == .help and s.nhits > 0) s.rows.at = @intCast(std.math.clamp(@as(i32, s.rows.at) + delta, 0, @as(i32, s.nhits) - 1));
+ return;
+ }
+ if (m.button == config.select_button and s.waits) {
+ s.waits = false;
+ v.active = point.id;
+ p.panes[point.id].?.focus = .body;
+ }
+ // The head's rows: the select button in its field puts the field's
+ // caret there (UX DESIGN M6); its words run and are looked at as a
+ // tag's.
if (point.head) {
- if (button != config.exec_button and button != config.look_button) return;
- const shown = (tagline.shownTag(p, arena, p.panes[point.id].?) catch return).text;
- var lines = std.mem.splitScalar(u8, shown, '\n');
- for (0..point.line) |_| _ = lines.next();
- const text = lines.next() orelse return;
- const b = tagline.wordBoundsAtCol(text, panes.File.rawAtDisplay(p.settings.tab, text, point.col)) orelse return;
+ const h = (pardes.TagState.head(p, arena, p.panes[point.id].?) catch return) orelse return;
+ const shown = tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, point.id)) catch return;
+ const text = modal.lineSlice(shown.text, point.line);
+ const raw = panes.File.rawAtDisplay(p.settings.tab, text, point.col);
+ if (m.button == config.select_button) {
+ const caret = h.caret orelse return;
+ const at = shown.toReal(modal.lineStartOffset(shown.text, point.line) + modal.graphemeStart(text, raw));
+ const start = caret - s.field.caret;
+ if (at >= start and at <= start + s.field.len) s.field.caret = @intCast(at - start);
+ return;
+ }
+ if (m.button != config.exec_button and m.button != config.look_button) return;
+ const b = tagline.wordBoundsAtCol(text, raw) orelse return;
if (b.lo == b.hi) return;
const word = text[b.lo..b.hi];
- if (v.tag_state.kind == .pick and button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", word);
- pardes.TagState.toRest(p);
- return exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", word);
+ if (!field) pardes.TagState.toRest(p);
+ return exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", word);
}
- if (button == config.select_button) {
- const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
- const ln = band.line(arena, p.settings.tab, point.line) catch return;
+ const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
+ const ln = band.line(arena, p.settings.tab, point.line) catch return;
+ if (m.button == config.select_button) {
for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) {
- pardes.TagState.point(p, part.row.index);
+ if (s.kind == .pick) pardes.Pick.press(p, part.row, false, false) else pardes.TagState.point(p, part.row.index);
};
return;
}
- if (button != config.exec_button and button != config.look_button) return;
- const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return;
- const kept = arena.dupe(u8, word) catch return;
- // A picker's band: B2 runs the word with the picker live (an act's word
- // acts, Pick.execWord); B3 on a row lands on it.
- if (v.tag_state.kind == .pick) {
- if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept);
- const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
- const ln = band.line(arena, p.settings.tab, point.line) catch return;
- for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) {
- pardes.TagState.point(p, part.row.index);
- return pardes.Pick.landHere(p);
+ if (m.button != config.exec_button and m.button != config.look_button) return;
+ // A picker's band: B3 on a row is Enter there (Pick.press); B2 runs the
+ // word under it with the picker up (an act's word acts, Pick.execWord).
+ if (s.kind == .pick and m.button == config.look_button) {
+ for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) {
+ return pardes.Pick.press(p, part.row, true, m.shift);
};
return;
}
- pardes.TagState.toRest(p);
- exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept);
+ const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return;
+ const kept = arena.dupe(u8, word) catch return;
+ if (s.kind != .pick) pardes.TagState.toRest(p);
+ exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", kept);
}
/// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen
@@ -2036,3 +2079,223 @@ test "one column's words at the window row's left and the window's at its right
clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0);
try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
}
+
+/// A picker asked from a held pane with three places in `dir`'s files,
+/// previewed in a reader made under it (UX DESIGN O1): the asker's id.
+fn heldPicker(p: *Pardes, tmp: *std.testing.TmpDir) !usize {
+ for ([_][]const u8{ "one.zig", "two.zig", "three.zig" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "const a = 1;\nconst b = 2;\nconst c = 3;\nconst d = 4;\n" });
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ pardes.Trail.keep(p.panes[held].?);
+ var rows: [3 * (std.Io.Dir.max_path_bytes + 32)]u8 = undefined;
+ const list = try std.fmt.bufPrint(&rows, "{s}/one.zig:2:1 Wrap b\n{s}/two.zig:3:1 c\n{s}/three.zig:4:1 d\n", .{ dir, dir, dir });
+ pardes.Pick.open(p, held, .list, "Refs", "", list);
+ p.update(.tick);
+ p.sync();
+ return held;
+}
+
+/// Screen row `i` of the band under pane `id`'s head, and a column on its
+/// rows' text.
+fn bandRow(p: *Pardes, id: usize, i: u16) [2]u16 {
+ const r = p.view().rects[id];
+ const at = pardes.Band.covered(p, p.panes[id].?, id);
+ return .{ r.x + TAG_TEXT_INSET + 8, r.y + at.tag + at.head + i };
+}
+
+test "the mouse never ends a picker as a side effect (UX DESIGN O2): the pointer's motion and the wheel anywhere leave it up; the wheel over its rows moves its cursor `wheel_rows` and the preview follows; B1 on a row puts the cursor there and keeps the keyboard in the field; B2 or B3 on the preview's text lands it first; Shift-B3 on a row opens it below" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const held = try heldPicker(p, &tmp);
+ const pk = pardes.Pick.live(p).?;
+ const reader = p.paneBySerial(pk.landing).?;
+ try std.testing.expect(reader != held and pk.made);
+ const s = &p.view().tag_state;
+ const rr = p.view().rects[reader];
+ // Motion and the wheel over the reader, over the held pane's body, and
+ // over the window row: nothing ends.
+ for ([_][2]u16{ .{ rr.x + 6, rr.y + 3 }, .{ 6, 0 } }) |at| {
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = at[0], .row = at[1] } });
+ p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = at[0], .row = at[1] } });
+ try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits);
+ }
+ try std.testing.expectEqual(held, p.view().active);
+ // The wheel over the rows: the cursor down, the next row previewed on
+ // the frame after.
+ const row0 = bandRow(p, held, 0);
+ p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = row0[0], .row = row0[1] } });
+ try std.testing.expectEqual(@as(u16, config.wheel_rows), s.rows.at);
+ p.update(.tick);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "two.zig"));
+ p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = row0[0], .row = row0[1] } });
+ try std.testing.expectEqual(@as(u16, 0), s.rows.at);
+ // B1 on the third row: the cursor there, the picker up, the keyboard
+ // its field's.
+ const row2 = bandRow(p, held, 2);
+ clickAt(p, .left, row2[0], row2[1]);
+ try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits);
+ try std.testing.expectEqual(@as(u16, 2), s.rows.at);
+ try std.testing.expectEqual(held, p.view().active);
+ p.update(.{ .key = .{ .cp = pardes.Key.up } });
+ try std.testing.expectEqual(@as(u16, 1), s.rows.at);
+ p.update(.{ .key = .{ .cp = pardes.Key.down } });
+ p.update(.tick);
+ p.sync();
+ // B3 on the preview's text: it lands first, the held pane's reader
+ // showing that file at that line, the picker gone.
+ const r2 = p.view().rects[reader];
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "three.zig"));
+ clickAt(p, .right, r2.x + config.GUTTER + 6, r2.y + p.panes[reader].?.tag_rows);
+ try std.testing.expect(pardes.Pick.live(p) == null);
+ const landed = pardes.Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[landed].?.file.?.path, "three.zig"));
+ // Shift-B3 on a row: that place in a new pane below.
+ p.view().active = held;
+ var n: usize = 0;
+ for (p.panes) |slot| n += @intFromBool(slot != null);
+ pardes.Pick.open(p, held, .list, "Refs", "", pk.rows);
+ p.sync();
+ const first = bandRow(p, held, 0);
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = first[0], .row = first[1], .shift = true } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = first[0], .row = first[1], .shift = true } });
+ try std.testing.expect(pardes.Pick.live(p) == null);
+ var now: usize = 0;
+ for (p.panes) |slot| now += @intFromBool(slot != null);
+ try std.testing.expectEqual(n + 1, now);
+ try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "one.zig"));
+}
+
+test "B1 in another pane: a picker waits (UX DESIGN O2), unrolled as it was, its box its pane's mode and no caret in its field; keys go where the keyboard is; B1 on its head, or C-w back to its pane, gives it the keyboard; Esc anywhere ends it first, then the pane's own Esc" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const held = try heldPicker(p, &tmp);
+ const pk = pardes.Pick.live(p).?;
+ const reader = p.paneBySerial(pk.landing).?;
+ const s = &p.view().tag_state;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // B1 on the preview: the keyboard there, the picker waiting.
+ const rr = p.view().rects[reader];
+ clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1);
+ try std.testing.expectEqual(reader, p.view().active);
+ try std.testing.expect(pardes.Pick.live(p) == pk and s.waits);
+ try std.testing.expectEqual(@as(?usize, held), pardes.TagState.hostOf(p));
+ const surface = try p.render(a);
+ const hr = p.view().rects[held];
+ try std.testing.expectEqualStrings(config.tag_normal, surface.at(hr.x, hr.y).grapheme());
+ try std.testing.expect(surface.cursor == null or surface.cursor.?.y >= rr.y);
+ // A key goes to the reader: `j` moves its caret, the field untouched.
+ const row = p.panes[reader].?.body.cur_row;
+ p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ try std.testing.expectEqual(row + 1, p.panes[reader].?.body.cur_row);
+ try std.testing.expectEqual(@as(u16, 0), s.field.len);
+ // B1 on the head: the keyboard back in the field.
+ const head = bandRow(p, held, 0);
+ clickAt(p, .left, head[0], head[1] - 1);
+ try std.testing.expect(!s.waits and p.view().active == held);
+ p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
+ try std.testing.expectEqualStrings("w", s.field.text());
+ // C-w to the held pane from the reader gives it back too.
+ clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1);
+ try std.testing.expect(s.waits);
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'k', .text = "k" } });
+ p.update(.{ .key = .{ .cp = pardes.Key.enter } });
+ try std.testing.expect(!s.waits and p.view().active == held and pardes.Pick.live(p) == pk);
+ // The keyboard to the held pane's own text under the band, in insert
+ // mode; Esc ends the picker first, the text still inserting; the next
+ // Esc is the text's.
+ const at = pardes.Band.covered(p, p.panes[held].?, held);
+ clickAt(p, .left, hr.x + config.GUTTER + 3, hr.y + at.tag + at.over);
+ try std.testing.expect(s.waits and p.view().active == held);
+ p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
+ try std.testing.expect(p.panes[held].?.body.mode == .insert);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest and !s.waits);
+ try std.testing.expect(p.panes[held].?.body.mode == .insert);
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(p.panes[held].?.body.mode == .normal);
+}
+
+test "B1 on the asking pane's own tag: the picker waits, the tag's text has the keyboard; a word there that changes nothing leaves it up; B2 Del ends it first, as Esc does, and closes the pane (UX DESIGN O2, O3)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const held = try heldPicker(p, &tmp);
+ const s = &p.view().tag_state;
+ p.panes[held].?.tag.own = try p.gpa.dupe(u8, "Wrap");
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const tag = try tagline.tagText(p, frame.allocator(), p.panes[held].?);
+ const hr = p.view().rects[held];
+ const col = struct {
+ fn of(q: *Pardes, t: []const u8, x: u16, word: []const u8) u16 {
+ return x + TAG_TEXT_INSET + 1 + @as(u16, @intCast(panes.File.displayWidth(q.settings.tab, t[0..std.mem.indexOf(u8, t, word).?])));
+ }
+ }.of;
+ clickAt(p, .left, col(p, tag, hr.x, "Wrap"), hr.y);
+ try std.testing.expect(pardes.Pick.live(p) != null and s.waits);
+ try std.testing.expectEqual(Pane.Focus.tag, p.panes[held].?.focus);
+ const wrapped = p.settings.wrap;
+ clickAt(p, .middle, col(p, tag, hr.x, "Wrap"), hr.y);
+ try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) != null);
+ var n: usize = 0;
+ for (p.panes) |slot| n += @intFromBool(slot != null);
+ clickAt(p, .middle, col(p, tag, hr.x, "Del"), hr.y);
+ try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest);
+ try std.testing.expect(p.panes[held] == null);
+ var now: usize = 0;
+ for (p.panes) |slot| now += @intFromBool(slot != null);
+ // The held pane and the reader made for the picker, both gone.
+ try std.testing.expectEqual(n - 2, now);
+}
+
+test "the act step and the rows under the mouse (UX DESIGN O2): B2 on an act's word acts and the picker stays, B2 on a row's word runs it and the picker stays, B1 on an act puts the act step's cursor on it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const held = try heldPicker(p, &tmp);
+ const pk = pardes.Pick.live(p).?;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // B2 on `Wrap` in the first row's text.
+ const band = (try pardes.Band.of(p, a, p.panes[held].?, held)).?;
+ const ln = try band.line(a, p.settings.tab, 0);
+ const r = p.view().rects[held];
+ const top = bandRow(p, held, 0)[1];
+ const wrap_col: u16 = r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, ln.text[0..std.mem.indexOf(u8, ln.text, "Wrap").?]))) + 1;
+ const wrapped = p.settings.wrap;
+ clickAt(p, .middle, wrap_col, top);
+ try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) == pk);
+ // M-l: the act step; B1 on `Copy` puts its cursor there, B2 on it
+ // copies the place, the picker up.
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ _ = frame.reset(.retain_capacity);
+ const acts = (try pardes.Band.of(p, a, p.panes[held].?, held)).?;
+ var copy: ?[2]u16 = null;
+ for (0..acts.height) |y| {
+ const l = try acts.line(a, p.settings.tab, @intCast(y));
+ if (std.mem.indexOf(u8, l.text, "y Copy")) |at| copy = .{ r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, l.text[0..at]))) + 3, top + @as(u16, @intCast(y)) };
+ }
+ clickAt(p, .left, copy.?[0], copy.?[1]);
+ try std.testing.expect(pk.spine == .acts and pardes.Pick.live(p) == pk);
+ try std.testing.expectEqual(@as(u8, 6), pk.act_at);
+ clickAt(p, .middle, copy.?[0], copy.?[1]);
+ try std.testing.expect(pardes.Pick.live(p) == pk);
+ try std.testing.expect(std.mem.endsWith(u8, p.registers.text(p.gpa, pardes.Registers.default).?, "one.zig:2\n"));
+}
diff --git a/core/panes.zig b/core/panes.zig
index 16b1d388..f4f528b7 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -1495,6 +1495,9 @@ pub fn paneDir(pane: *const Pane) []const u8 {
/// none by recency.
pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void {
const v = p.view();
+ // The pane a picker asks from or previews in: the picker ends first,
+ // as Esc ends it (UX DESIGN O3), a pane made for it gone with it.
+ pardes.Pick.yieldFor(p, id);
const pane = p.panes[id] orelse return;
// What is docked to it closes with it, first, each giving its rows
// back to it: then its rows, theirs among them, go where a pane's go.
diff --git a/core/tagline.zig b/core/tagline.zig
index 8e8c5d2d..eedc25bc 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -67,23 +67,48 @@ pub fn computedWords(pane: *const Pane) []const u8 {
// A kind's: its addon's words, then Del (Kind.reopen).
if (pane.addon) |k| if (k.tail.len > 0) return k.tail.slice();
if (pane.query) |q| return if (q.frozen) query_frozen_tail else if (q.capped) query_capped_tail else query_live_tail;
- if (pane.file) |*f| {
- if (f.output) |out| if (out.from == .preview) return query_live_tail;
- if (f.listing != null) return " Get Del";
- const j = &f.history.journal;
- var bits = fileBits(pane, f);
- if (!dirty(pane)) bits &= ~@as(usize, 4);
- // A step back with something in it: insert mode's mark is a step
- // of none until a key types (Text.Journal.mark keeps one such, on
- // top), and Undo would act on nothing.
- if (j.done == 0 or (j.done == 1 and j.steps.items[0].n == 0)) bits &= ~@as(usize, 8);
- if (j.done == j.steps.items.len) bits &= ~@as(usize, 16);
- return file_words[bits];
- }
+ if (pane.file) |*f| return fileWords(pane, f);
if (pane.command != null) return if (pane.command_done) " Del" else " Kill Del";
return " Del";
}
+/// The computed words a pane's tag shows, in and out of rest (UX DESIGN
+/// M1): its own (`computedWords`); while a picker previews another file in
+/// its body, its own file's, set aside under the preview (`named`); none
+/// in a pane made for the picker, whose tag is its owner's word alone.
+pub fn tagWords(p: *const Pardes, pane: *const Pane) []const u8 {
+ const pk = pardes.Pick.landingOf(p, pane) orelse return computedWords(pane);
+ if (pk.made) return "";
+ return fileWords(pane, named(p, pane) orelse return computedWords(pane));
+}
+
+/// The file pane `pane`'s tag names: its own, the one a picker's preview
+/// set aside in its body included (UX DESIGN M3: the tag says what Esc
+/// gives back and where Enter lands, never the preview); none in a pane
+/// made for the picker.
+pub fn named(p: *const Pardes, pane: *const Pane) ?*const panes.File.State {
+ if (pardes.Pick.landingOf(p, pane)) |pk| {
+ if (pk.made) return null;
+ if (pk.aside) |*own| return own;
+ }
+ return if (pane.file) |*f| f else null;
+}
+
+/// A file's computed words (UX K'3), file `f` its own.
+fn fileWords(pane: *const Pane, f: *const panes.File.State) []const u8 {
+ if (f.output) |out| if (out.from == .preview) return query_live_tail;
+ if (f.listing != null) return " Get Del";
+ const j = &f.history.journal;
+ var bits = fileBits(pane, f);
+ if (!unsaved(f)) bits &= ~@as(usize, 4);
+ // A step back with something in it: insert mode's mark is a step
+ // of none until a key types (Text.Journal.mark keeps one such, on
+ // top), and Undo would act on nothing.
+ if (j.done == 0 or (j.done == 1 and j.steps.items[0].n == 0)) bits &= ~@as(usize, 8);
+ if (j.done == j.steps.items.len) bits &= ~@as(usize, 16);
+ return file_words[bits];
+}
+
/// The computed words pane `pane` can come to show (K'3: Save, Undo and
/// Redo come and go with its edits, a query's as it freezes): what a
/// placement leaves its tag the rows for (layout.minRows), so an edit
@@ -91,7 +116,7 @@ pub fn computedWords(pane: *const Pane) []const u8 {
/// own (its first edit holds it): its walk folds to the rows it has with
/// them (`folded`).
pub fn widestWords(p: *const Pardes, pane: *const Pane) []const u8 {
- if (pardes.Trail.reading(p, pane)) return computedWords(pane);
+ if (pardes.Trail.reading(p, pane)) return tagWords(p, pane);
if (pane.query != null) return query_frozen_tail;
if (pane.file) |*f| if (f.listing == null and (if (f.output) |out| out.from != .preview else true))
return file_words[fileBits(pane, f)];
@@ -111,7 +136,11 @@ fn fileBits(pane: *const Pane, f: *const panes.File.State) usize {
}
/// A file with changes it has not saved.
pub fn dirty(pane: *const panes.Pane) bool {
- const f = pane.file orelse return false;
+ return if (pane.file) |*f| unsaved(f) else false;
+}
+
+/// Whether file `f` has changes it has not saved (`dirty`, `fileWords`).
+fn unsaved(f: *const panes.File.State) bool {
return panes.Output.fileTraits(f.output).saves and (f.revision != f.saved_revision or f.disk_gone);
}
/// What a column's tag said before UX K', its own text then: a dump's own
@@ -249,27 +278,17 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
}
/// The computed start of a pane's tag -- its path, a PDF's page, a
-/// terminal's directory -- without its computed words (restPrefix). It is
-/// never stored, and never edited.
+/// terminal's directory -- without its computed words (restPrefix): the
+/// same in every state (UX DESIGN M1). It is never stored, and never
+/// edited.
pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
- // Out of rest (UX D1) the owner's word and the newest step's, each with
- // its ` › `, before the head: the path, the forward steps and Keep
- // hidden until rest (a picker's preview is no name of the pane's).
- if (pardes.Trail.outOfRest(p, pane)) {
- if (pane.trail.n == 0) return "";
- const room = try arena.alloc(u8, pane.trail.bytes(.newest, 1));
- var w: std.Io.Writer = .fixed(room);
- pane.trail.write(.newest, 1, &w) catch return error.OutOfMemory;
- return w.buffered();
- }
- return restPath(p, arena, pane);
-}
-
-/// The computed start of a pane's tag at rest, whatever its state: what
-/// the tag's own text follows.
-fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
+ // A pane a picker previews in names itself, never the preview (UX
+ // DESIGN M3): its own file, or where it was made for the picker, which
+ // has no rest, its owner's word alone.
+ const landing = pardes.Pick.landingOf(p, pane);
+ if (landing) |pk| if (pk.made) return std.fmt.allocPrint(arena, "‹" ++ config.pane_addr ++ "{d} ›", .{pk.owner});
// What is drawn: with no graphics, glyph art whatever `Petscii` says.
- if (pane.addon != null) return pardes.Kind.prefix(p, arena, pane);
+ if (pane.addon != null and landing == null) return pardes.Kind.prefix(p, arena, pane);
// A command pane: its directory, the line it runs, and how that went.
// Its first line only, cut to 48 bytes at a character's start: a tag's
// first row is where the prefix ends, and a line that ran over to a
@@ -300,7 +319,7 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8
// Unsaved text shows on the grip, as acme's modbutton does, not as a
// mark in the text: the prefix is the name alone, and Keep after it
// while a jump would step it (Trail.zig).
- if (pane.file) |f| {
+ if (named(p, pane)) |f| {
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
const keep = pardes.Trail.reading(p, pane);
if (pane.trail.n == 0 and !keep) return name;
@@ -360,7 +379,7 @@ pub const Fold = struct {
/// as a tag at rest wraps (UX E4, P1's reading 9).
pub fn folded(p: *const Pardes, pane: *const Pane) Fold {
const t = &pane.trail;
- const f = pane.file orelse return .{};
+ const f = named(p, pane) orelse return .{};
if (t.n == 0) return .{};
const id = panes.paneIdOf(p, pane) orelse return .{};
const tab = p.settings.tab;
@@ -369,7 +388,7 @@ pub fn folded(p: *const Pardes, pane: *const Pane) Fold {
const keep = pardes.Trail.reading(p, pane);
const tail = curTail(pane);
// Its computed words and the blank before its own text (restPrefix).
- const words = panes.File.displayWidth(tab, computedWords(pane)) + 1;
+ const words = panes.File.displayWidth(tab, tagWords(p, pane)) + 1;
const bare = panes.File.displayWidth(tab, name) + @as(usize, if (keep) " Keep".len else 0) + words + panes.File.displayWidth(tab, tail);
var whole: usize = pardes.Trail.shown_steps;
while (whole > 1 and rowsOf(bare + walkCells(t, whole, tab), width) > rowsOf(bare, width)) whole -= 1;
@@ -429,8 +448,8 @@ fn rowsOf(cells: usize, width: usize) usize {
/// The bytes of a file's tag its walk's forward steps take, after its name.
pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize {
- const f = pane.file orelse return .{ 0, 0 };
- if (pane.trail.n == 0 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 };
+ const f = named(p, pane) orelse return .{ 0, 0 };
+ if (pane.trail.n == 0) return .{ 0, 0 };
const fold = folded(p, pane);
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
const dots: usize = if (fold.cut > 0) "…".len else 0;
@@ -442,7 +461,6 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize {
/// text, if one is there.
pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 {
if (pane.trail.n == 0 or pane.file == null) return null;
- if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at);
const whole = folded(p, pane).whole;
const ahead = forwardSpan(p, pane);
if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at);
@@ -466,11 +484,10 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 {
return prefixIn(p, p.scratch.allocator(), pane);
}
-/// The prefix as the tag shows it, built in `arena`.
+/// The prefix as the tag shows it, built in `arena`: a question follows
+/// the path, in place of the computed words.
pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 {
- // Out of rest the head follows: its words end in their own space; a
- // question at rest follows the path, in place of the computed words.
- if (pardes.Trail.outOfRest(p, pane) or TagState.asks(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane));
+ if (TagState.asks(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane));
return restPrefix(p, arena, pane);
}
@@ -482,13 +499,13 @@ pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 {
/// with the own text's first word against `Del`, Look and Exec would see
/// one word.
pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 {
- return prefixWith(p, arena, pane, computedWords(pane));
+ return prefixWith(p, arena, pane, tagWords(p, pane));
}
/// The prefix at rest with computed words `words` (restPrefix's own, or
/// the widest its pane can come to show, widestWords).
pub fn prefixWith(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane, words: []const u8) ![]u8 {
- return std.mem.concat(arena, u8, &.{ try restPath(p, arena, pane), words, " " });
+ return std.mem.concat(arena, u8, &.{ try pathPrefix(p, arena, pane), words, " " });
}
/// The tag's own text: the user's (UX K'1), everything typed into the tag
@@ -530,12 +547,12 @@ pub fn kindTail(pane: *const Pane) []const u8 {
return pane_tail;
}
-/// What the tag shows after its prefix: its own text, or while the pane
-/// is out of rest in this view the head (TagState.head: the keys, the
-/// level, the field), computed and read-only, the own text untouched under
-/// it and back at rest (walk UI R1).
+/// What the tag shows after its prefix: its own text, or while a question
+/// waits on it the question (TagState.asking), computed and read-only, the
+/// own text untouched under it. Out of rest the same: the head hangs under
+/// the tag (UX DESIGN M1).
pub fn shownTail(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
- if (try TagState.head(p, arena, pane)) |h| return h.text;
+ if (try TagState.asking(p, arena, pane)) |h| return h.text;
return curTail(pane);
}
@@ -672,7 +689,7 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso
/// words; null off it.
pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize {
const tab = p.settings.tab;
- if (row + pane.tag_top != 0 or pardes.Trail.outOfRest(p, pane)) return null;
+ if (row + pane.tag_top != 0) return null;
const f = pane.file orelse return null;
if (!panes.Output.fileTraits(f.output).saves) return null;
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
diff --git a/core/views.zig b/core/views.zig
index 3b238258..75e2e5d9 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -615,7 +615,7 @@ test "a view not live with its band open, dumped and loaded, draws before its ne
test "a picker's band in a short column, dumped and loaded: its rows are the never-loaded session's, and so is the next layout" {
const gpa = std.testing.allocator;
const dump = @import("dump.zig");
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 });
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 14 });
defer p.deinit();
p.settings.jumps = .walk;
var tmp = std.testing.tmpDir(.{});
@@ -631,17 +631,17 @@ test "a picker's band in a short column, dumped and loaded: its rows are the nev
const low = p.view().active;
p.view().active = host;
p.sync();
- // Find in the pane itself (it reads): its head and its act row over
- // the band, which the short column holds under what it wants.
+ // Find in the pane itself (it reads): its head over the band, which
+ // the short column holds under what it wants.
p.stream.engine = .walk;
pardes.Pick.open(p, host, .find, "", "", "");
p.sync();
const at = pardes.Band.covered(p, pane, host);
try testing.expect(at.band > 0 and at.band < pardes.Band.takes(p, host));
- try testing.expect(at.text >= 2);
+ try testing.expect(at.head == 1);
const bytes = try dump.byteDump(p);
defer gpa.free(bytes);
- const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, null);
+ const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 14 }, bytes, null);
defer q.deinit();
try testing.expectEqual(pane.view.covered, q.panes[host].?.view.covered);
try testing.expectEqual(pane.tag_rows, q.panes[host].?.tag_rows);