diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 22:16:38 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 22:16:38 -0300 |
| commit | b44a129a8854483dbe45ce2bcfa09f33ccbd6e8c (patch) | |
| tree | 3038f283024ebee6dd73fbea186e0383ee89c9da /core/Band.zig | |
| parent | 7bac0f3d594b029a3631687ec3d8dd3626e0f447 (diff) | |
| download | pardes-b44a129a8854483dbe45ce2bcfa09f33ccbd6e8c.tar.gz pardes-b44a129a8854483dbe45ce2bcfa09f33ccbd6e8c.zip | |
registers: `"` shows the registers rolled in the tag, each its key and the first line of its value (`" ▸ " self.dirty = true; a const best = rank(q, nam… / — … % core/x.zig . o # 1 _ —`), `↓` unrolls them a row each (key, what it is, first line) beside the cursor's value in full, and choosing one (its key, or Enter) goes down to its verbs rolled (`" a ▸ p after P before R replace y into`), Backspace back up, Esc to rest (pick-ui SPEC §9, walk UI line F item 1): the level is built from the registers (and the four computed from the pane with the keyboard) when it is read, as the addon words join SPC's (bindings.registerLevel, registerValue: the first value only, a first line cut at 24 columns and never scanned past 96 bytes, the value step reading only the lines the band shows); a register named (`t.normal.register`, the parser's) is the root `"` with that key as its path (TagState.current), its verbs a node of normal mode's paste, yank and replace roles (bindings.register_verbs, a group slot of its own: TagState.used one longer, the dump with it); keys.prefixKey reads the level at the current path, Esc there goes to rest (normal mode's Esc would have named the register ESC, then left the pane), Backspace from the verbs goes back to `"`; TEST: bindings.zig "\" shows the registers rolled ..." (the level, the band's rows and value, Enter, Backspace, `a p` pasting, Esc); core-test 1024/1191 (167 skipped), 0 failed, load 5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Band.zig')
| -rw-r--r-- | core/Band.zig | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/core/Band.zig b/core/Band.zig index 3c800bf0..13c4b9c0 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -105,6 +105,8 @@ pub fn takes(p: *Pardes, id: usize) u16 { const cur = TagState.current(p, v) orelse return 0; var children: [bindings.max_children]bindings.Child = undefined; const n: u16 = @intCast(bindings.level(p, cur.root, cur.path, &children).len); + // The registers, one column of eleven at most (registerSteps). + if (cur.root == .register and cur.path.len == 0) return @max(doc_rows, @min(Cursor.shown, n)); return @max(doc_rows, levelRows(n)); } @@ -151,6 +153,11 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { }, } const cur = TagState.current(p, v).?; + if (cur.root == .register) { + try band.registerSteps(p, arena, pane, cur.path); + try band.place(p, arena, pane, id); + return band; + } // The level, its cursor on the child it names, else the leaf its group // ran last, else the first; and that child's doc beside it. const node = bindings.nodeAt(cur.root, cur.path); @@ -196,6 +203,63 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta band.add(try docStep(p, arena, at.root, at.path[0 .. at.path.len - 1], at.child)); } +/// `"` unrolled (SPEC §9): the registers, a row each (its key, what it +/// is, its first line) around the cursor, or under `"a` its verbs; beside +/// them the value of the one on the cursor (or named) in full, as many of +/// its lines as the band has rows, only those read. +fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const Pane, path: []const u8) !void { + const s = &p.view().tag_state; + var children: [bindings.max_children]bindings.Child = undefined; + const level = bindings.level(p, .register, path, &children); + const node = bindings.nodeAt(.register, path); + const used = if (node) |n| s.used[n.group] else 0; + var at: usize = 0; + for (level, 0..) |c, i| if (c.key == (if (s.hi != 0) s.hi else used)) { + at = i; + }; + if (path.len > 0) band.add(try levelStep(arena, pane, level, at, used)) else { + const w = (Cursor{ .at = @intCast(at) }).window(@intCast(level.len)); + const rows = try arena.alloc(Row, w.hi - w.lo); + for (rows, w.lo..) |*row, i| { + const c = level[i]; + const name = for (bindings.register_names) |r| { + if (r.key == c.key) break r.name; + } else "named"; + row.* = .{ + .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }), + .on = i == at, + .key = 1, + .under = c.key == used, + .index = @intCast(i), + }; + } + band.add(.{ .rows = rows }); + } + const key = if (path.len > 0) path[0] else level[at].key; + const name = for (bindings.register_names) |r| { + if (r.key == key) break r.name; + } else "named"; + var rows: std.ArrayList(Row) = .empty; + try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "\"{s} · {s}", .{ bindings.keyName(key), name }), .key = 2 }); + const value = bindings.registerValue(p, key); + if (value.len == 0) try rows.append(arena, .{ .text = "(empty)", .dim = true }); + // A line is cut at what the band could show of it: a long one is + // never scanned past that. + const most = @as(usize, band.columns) * band.height; + var rest = value; + while (rest.len > 0 and rows.items.len + 1 < band.height) { + const look = rest[0..@min(rest.len, most)]; + const end = std.mem.indexOfScalar(u8, look, '\n') orelse { + try rows.append(arena, .{ .text = rest[0..if (look.len < rest.len) modal.graphemeStart(rest, look.len) else look.len] }); + break; + }; + try rows.append(arena, .{ .text = look[0..end] }); + rest = rest[end + 1 ..]; + } + if (path.len == 0) try rows.append(arena, .{ .text = "next p after P before R replace y into", .dim = true }); + band.add(.{ .rows = rows.items, .doc = true }); +} + /// A list's cursor and the rows of it a band shows: eleven at most, around /// the cursor (SPEC §3.6, the prototype's `H.window`). Each view's (a /// tag state's field): Help's rows, a picker's, a prompt's history. @@ -245,7 +309,7 @@ pub fn levelStep(arena: std.mem.Allocator, pane: *const Pane, level: []const bin for (level, rows, 0..) |c, *row, i| { const key = bindings.keyName(c.key); row.* = .{ - .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group) "…" else "" }), + .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group or c.more) "…" else "" }), .on = i == at, .key = @intCast(key.len), .dim = bindings.dimmed(pane, c), |
