summaryrefslogtreecommitdiff
path: root/core/Band.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Band.zig')
-rw-r--r--core/Band.zig76
1 files changed, 75 insertions, 1 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 5e399cba..835c249f 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -27,6 +27,7 @@ const panes = @import("panes.zig");
const builtins = @import("builtins.zig");
const TagState = @import("TagState.zig");
const Names = @import("Names.zig");
+const Prompt = @import("Prompt.zig");
const Pardes = pardes.Pardes;
const Pane = pardes.Pane;
const File = panes.File;
@@ -100,11 +101,15 @@ pub fn takes(p: *Pardes, id: usize) u16 {
return @max(doc_rows, levelRows(@intCast(bindings.level(p, s.scope_root.?, s.scope[0 .. s.scope_n - 1], &children).len)));
},
.pick => return @import("Pick.zig").bandRows(p),
+ .prompt => return Prompt.takes(p),
+ .rename => return 0,
}
if (!s.unrolled) return 0;
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));
}
@@ -149,8 +154,20 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band {
try band.place(p, arena, pane, id);
return band;
},
+ .prompt => {
+ var steps: [max_steps]Step = undefined;
+ for (try Prompt.steps(p, arena, &steps)) |step| band.add(step);
+ try band.place(p, arena, pane, id);
+ return band;
+ },
+ .rename => return null,
}
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 +213,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 +319,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),