diff options
Diffstat (limited to 'core/Band.zig')
| -rw-r--r-- | core/Band.zig | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/core/Band.zig b/core/Band.zig index 835c249f..a8d97bb4 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -39,6 +39,9 @@ pub const Row = struct { on: bool = false, /// Its first `key` bytes are a key: the key ink, bold. key: u8 = 0, + /// Its first `chord` bytes are a chord (Help's `SPC h t`): the key ink + /// at the text's weight. + chord: u8 = 0, dim: bool = false, /// The leaf its group ran last. under: bool = false, @@ -205,7 +208,9 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta const low = try std.ascii.allocLowerString(arena, leaf.row); _ = Names.match(q, leaf.row, low, 0, &marks, &nmarks); } - row.* = .{ .text = leaf.row, .on = i == s.rows.at, .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) }; + // 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) }; } band.add(.{ .rows = rows }); var buf: [TagState.row_max]u8 = undefined; @@ -351,6 +356,8 @@ pub fn docStep(p: *Pardes, arena: std.mem.Allocator, root: bindings.Root, path: .role => bindings.docOf(root, c, try arena.alloc(u8, 160)), } else bindings.docOf(root, c, &.{}); try rows.append(arena, .{ .text = doc }); + // A leaf a language server answers, in a pane with none (SPEC §4.2). + if (bindings.dimmed(p.panes[p.view().active].?, c)) try rows.append(arena, .{ .text = "needs a language server", .dim = true }); var buf: [64]u8 = undefined; const here = try std.mem.concat(arena, u8, &.{ path, &.{c.key} }); try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "keys {s}", .{bindings.chord(root, here, &buf)}) }); @@ -653,3 +660,71 @@ test "a doc's paragraphs are rows of their own: no newline in a band's row" { }; try std.testing.expect(docs > 2); } + +test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a chord in the key ink, a matched letter bold in the match ink on its row's own ground, the cursor row's too; an LSP leaf with no server in the dim ink, never faint, its doc saying why" { + const Key = pardes.Key; + 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 roles = &p.chromeTheme().roles; + const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + const selected = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + // Help with `wrap` typed: `▶ SPC t w · Wrap · view` on the cursor row. + for ([_]u21{ ' ', '?', 'w', 'r', 'a', 'p' }) |c| p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + var layer = bandLayer(p, id).?; + var spines: usize = 0; + var cursor_row: ?usize = null; + for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| { + try std.testing.expect(!cell.style.dim); + if (std.mem.eql(u8, cell.grapheme(), "│")) { + try std.testing.expectEqual(pardes.Color{ .rgb = inks.rule }, cell.style.fg); + spines += 1; + } + if (std.mem.eql(u8, cell.grapheme(), "▶")) cursor_row = row; + }; + try std.testing.expect(spines > 0); + const on = layer.cells[cursor_row.? * layer.cols ..][0..layer.cols]; + const s_cell = on[Cells.find(on, "SPC t w").?]; + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s_cell.style.fg); + try std.testing.expect(!s_cell.style.bold); + var matched: usize = 0; + for (on) |cell| if (std.meta.eql(cell.style.fg, pardes.Color{ .rgb = roles.match })) { + try std.testing.expect(cell.style.bold); + try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg); + matched += 1; + }; + try std.testing.expect(matched >= 4); + p.update(.{ .key = .{ .cp = Key.escape } }); + // SPC l unrolled in a text file no server speaks for: its leaves dim. + for ([_]u21{ ' ', 'l', Key.down }) |c| p.update(.{ .key = .{ .cp = c } }); + _ = try p.render(a); + layer = bandLayer(p, id).?; + var dimmed: usize = 0; + var why = false; + for (0..layer.rows) |row| { + const cells = layer.cells[row * layer.cols ..][0..layer.cols]; + if (Cells.find(cells, "needs a language server") != null) why = true; + const cell = cells[Cells.find(cells, "Hover") orelse continue]; + try std.testing.expect(!cell.style.dim); + try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg); + dimmed += 1; + } + try std.testing.expect(dimmed > 0 and why); +} |
