diff options
| -rw-r--r-- | core/Band.zig | 68 | ||||
| -rw-r--r-- | test/process/tty_terminals.zig | 2 | ||||
| -rw-r--r-- | test/snapshots/ttyhelp.golden | 8 |
3 files changed, 66 insertions, 12 deletions
diff --git a/core/Band.zig b/core/Band.zig index f03a2c53..f2a86d07 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -215,8 +215,9 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { return band; } -/// Help's rows (`chord · word · group`, the query's bytes in the match -/// tint) around the cursor, and the cursor's leaf's doc beside them. +/// Help's rows around the cursor (`SPC t w Wrap`, the query's bytes in +/// the match tint, the group `view` its meta: UX D5), and the cursor's +/// leaf's doc beside them. fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagState) !void { if (s.nhits == 0) { const none = try arena.alloc(Row, 1); @@ -230,15 +231,18 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta for (rows, w.lo..) |*row, i| { const buf = try arena.create([TagState.row_max]u8); const leaf = TagState.helpLeaf(p, s.hits[i], buf); + // Its leaf's `chord · word · group` as the chord (the key ink), two + // blanks and the word; the group its meta (dim, at the right). + var parts = std.mem.splitSequence(u8, leaf.row, " · "); + const chord = parts.first(); + const text = try std.mem.concat(arena, u8, &.{ chord, " ", parts.next() orelse "" }); var marks: [Names.max_query * 4]u16 = undefined; var nmarks: usize = 0; if (std.mem.trim(u8, q, " ").len > 0) { - const low = try std.ascii.allocLowerString(arena, leaf.row); - _ = Names.match(q, leaf.row, low, 0, &marks, &nmarks); + const low = try std.ascii.allocLowerString(arena, text); + if (Names.match(q, text, low, 0, &marks, &nmarks) == null) nmarks = 0; } - // Its chord (`SPC h t`, before the first ` · `) in the key ink. - const chord = std.mem.indexOf(u8, leaf.row, " · ") orelse 0; - row.* = .{ .text = leaf.row, .on = i == s.rows.at, .chord = @intCast(@min(chord, 255)), .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) }; + row.* = .{ .text = text, .meta = parts.rest(), .on = i == s.rows.at, .chord = @intCast(@min(chord.len, 255)), .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) }; } band.add(.{ .rows = rows }); var buf: [TagState.row_max]u8 = undefined; @@ -460,6 +464,12 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi kept += 1; } band.nsteps = kept; + // The last step, a list, takes what the band has left (UX E3): 52 cells + // only when a step follows it; its meta at the band's right edge. + if (kept > 0 and !band.steps[kept - 1].doc and !band.steps[kept - 1].two) { + const last = &band.steps[kept - 1]; + last.width = @max(last.width, band.columns -| last.x); + } } /// The display columns of the head's key cells: a spine hangs under each, @@ -702,6 +712,50 @@ test "steps stand apart: one blank, the rule, one blank between a step and the n }; } +test "Help's rows say the chord, two blanks and the word; the group is the row's meta, right-aligned at its step's edge in the dim ink: no ` · ` (UX D5, D4)" { + const Cells = struct { + /// The cell `word` starts at, a grapheme a cell. + fn find(cells: []const pardes.Cell, word: []const u8) ?usize { + var at: usize = 0; + while (at + word.len <= cells.len) : (at += 1) { + for (word, cells[at..][0..word.len]) |c, cell| { + if (cell.len != 1 or cell.text[0] != c) break; + } else return at; + } + return null; + } + }; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const selected = p.chromeTheme().roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + for ([_]u21{ ' ', '?', 'w', 'r', 'a', 'p' }) |c| p.update(.{ .key = .{ .cp = c } }); + const band = (try of(p, a, pane, id)).?; + const step = band.steps[0]; + var found = false; + for (step.rows) |row| { + try std.testing.expect(std.mem.indexOf(u8, row.text, " · ") == null); + if (!std.mem.eql(u8, row.text, "SPC t w Wrap")) continue; + try std.testing.expectEqualStrings("view", row.meta); + found = true; + } + try std.testing.expect(found); + _ = try p.render(a); + const layer = bandLayer(p, id).?; + for (0..layer.rows) |y| { + const cells = layer.cells[y * layer.cols ..][0..layer.cols]; + if (Cells.find(cells, "SPC t w Wrap") == null) continue; + const at = Cells.find(cells, "view").?; + try std.testing.expectEqual(@as(usize, step.x + step.width - "view".len), at); + try std.testing.expectEqual(pardes.Color{ .rgb = selected.dim }, cells[at].style.fg); + break; + } else return error.TestUnexpectedResult; +} + test "a row longer than its room is cut with `…`: a path from the left, anything else from the right, its marks and faint bytes moved with it" { var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); diff --git a/test/process/tty_terminals.zig b/test/process/tty_terminals.zig index 53050a18..a49d3696 100644 --- a/test/process/tty_terminals.zig +++ b/test/process/tty_terminals.zig @@ -232,7 +232,7 @@ fn ttyhelp(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("space"); try t.key("?"); try t.send("tutor"); - try t.wait(10000, "SPC h t · Tutor · help"); + try t.wait(10000, "SPC h t Tutor"); try t.stable(700, 15000); try t.snap("leaderworks"); try t.done(); diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index 41f429e0..7217e5ba 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -50,10 +50,10 @@ |30: ✓ @p1 Help 1 message · SPC h m == snap leaderworks grid=100x31 cursor=12,5 |5: ^ Help tutor 1/1 -|6: ▶ SPC h t · Tutor · help │ t Tutor -|7: │ Open the tutor, a document to work through. -|8: │ keys SPC h t -|9: │ +|6: ▶ SPC h t Tutor help │ t Tutor +|7: │ Open the tutor, a document to work through. +|8: │ keys SPC h t +|9: │ |10: 1 pardes builtins: each one's keys and its name, then what it does. Run one by its keys, or by↩ |11: its name anywhere: B2 on the word, Exec <name>, a line of a ctl file, or `pardes do <name>`↩ |12: from a shell. `Help <name>` shows one builtin alone; `Help <keys>` (or SPC, those keys, the↩ |
