summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig31
-rw-r--r--core/TagState.zig20
-rw-r--r--core/bindings.zig70
-rw-r--r--core/draw.zig6
4 files changed, 113 insertions, 14 deletions
diff --git a/core/Band.zig b/core/Band.zig
index e562da1d..5ddbe5af 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -59,6 +59,11 @@ pub const Row = struct {
/// Said at the row's right end in the dim ink, two cells off its text
/// at least, and the first to give way (UX D5): `in use`.
meta: []const u8 = "",
+ /// Its bytes `quiet[0]..quiet[1]` in the dim ink: an empty register's
+ /// `—`, a value's `⏎`.
+ quiet: [2]u16 = .{ 0, 0 },
+ /// Bytes that are keys, each in the key ink, bold: a register's verbs.
+ keys: []const u16 = &.{},
};
/// A column of rows. A level of more than 9 rows flows into two columns
@@ -221,6 +226,18 @@ 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));
}
+/// What a register's doc step offers next, its letters keys (UX D11).
+const verbs = "p after P before R replace y into";
+const verb_keys = blk: {
+ var out: [4]u16 = undefined;
+ var n: usize = 0;
+ for (0..verbs.len) |i| if (i == 0 or (i >= 2 and std.mem.eql(u8, verbs[i - 2 .. i], " "))) {
+ out[n] = i;
+ n += 1;
+ };
+ break :blk out;
+};
+
/// `"` 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
@@ -238,17 +255,25 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const
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);
+ // A row each (UX D11): `key value`, its name at the right; an
+ // empty one's `—` and a newline's `⏎` dim.
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";
+ const key = bindings.keyName(c.key);
+ const shown = try bindings.registerShown(arena, p.settings.tab, bindings.registerValue(p, c.key));
+ const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ key, shown });
+ const quiet = if (std.mem.eql(u8, shown, "—")) key.len + 2 else if (std.mem.endsWith(u8, shown, "⏎")) text.len - "⏎".len else text.len;
row.* = .{
- .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }),
+ .text = text,
.on = i == at,
- .key = 1,
+ .key = @intCast(key.len),
.under = c.key == used,
.index = @intCast(i),
+ .meta = name,
+ .quiet = .{ @intCast(quiet), @intCast(text.len) },
};
}
band.add(.{ .rows = rows });
@@ -274,7 +299,7 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const
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 });
+ if (path.len == 0) try rows.append(arena, .{ .text = verbs, .dim = true, .keys = &verb_keys });
band.add(.{ .rows = rows.items, .doc = true });
}
diff --git a/core/TagState.zig b/core/TagState.zig
index 0a59bd08..7a34ed77 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -588,19 +588,31 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
var children: [bindings.max_children]bindings.Child = undefined;
const level = bindings.level(p, cur.root, cur.path, &children);
const used = s.used[node.group];
+ // The registers rolled (UX D11): the ones holding something, each its
+ // value as a row shows it, a newline's `⏎` dim.
+ const registers = cur.root == .register and cur.path.len == 0;
var width = panes.File.displayWidth(tab, b.text.items);
+ var put: usize = 0;
for (level, 0..) |c, i| {
- width += @as(usize, if (i == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group);
+ const value = if (registers) bindings.registerValue(p, c.key) else "";
+ if (registers and value.len == 0) continue;
+ const label = if (registers) try bindings.registerShown(arena, tab, value) else c.label;
+ const cut = c.group or (c.more and !registers);
+ width += @as(usize, if (put == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, label) + @intFromBool(cut);
if (width + @as(usize, if (i + 1 < level.len) panes.File.displayWidth(tab, more) else 0) > room) {
try b.put(more);
break;
}
- try b.put(if (i == 0) " " else " ");
+ try b.put(if (put == 0) " " else " ");
+ put += 1;
const lo: u32 = @intCast(b.text.items.len);
try b.styled(bindings.keyName(c.key), .key);
try b.put(" ");
- try b.put(c.label);
- if (c.group or c.more) try b.put("…");
+ if (registers and std.mem.endsWith(u8, label, "⏎")) {
+ try b.put(label[0 .. label.len - "⏎".len]);
+ try b.styled("⏎", .dim);
+ } else try b.put(label);
+ if (cut) try b.put("…");
const hi: u32 = @intCast(b.text.items.len);
if (bindings.dimmed(pane, c)) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .dim });
if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under });
diff --git a/core/bindings.zig b/core/bindings.zig
index 2df51945..96ce1359 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -338,8 +338,30 @@ pub const register_names = [_]struct { key: u8, name: []const u8 }{
};
/// The display columns of a register's first line which-key shows; the
-/// rest is `…`.
-pub const register_cut = 24;
+/// rest is `…` (UX D11: 20 cells, the `…` among them).
+pub const register_cut = 20;
+
+/// A register's value as a row shows it (UX D11): its first line in
+/// `register_cut` cells at most, a path cut from the left
+/// (`…core/Query.zig`), other text from the right (`…` after it), a newline
+/// that ends what shows said `⏎`; `—` when it holds nothing. Only its first
+/// `4 * register_cut` bytes are read.
+pub fn registerShown(arena: std.mem.Allocator, tab: u16, value: []const u8) ![]const u8 {
+ if (value.len == 0) return "—";
+ const bound = if (value.len > 4 * register_cut) modal.graphemeStart(value, 4 * register_cut) else value.len;
+ const newline = std.mem.indexOfScalar(u8, value[0..bound], '\n');
+ const line = value[0 .. newline orelse bound];
+ const width = File.displayWidth(tab, line);
+ if (width <= register_cut and line.len == value.len) return line;
+ if (width < register_cut and newline != null) return std.mem.concat(arena, u8, &.{ line, "⏎" });
+ // A path: one line, no spaces, a slash in it; its end says which file.
+ if (newline == null and bound == value.len and std.mem.indexOfAny(u8, line, " \t") == null and std.mem.indexOfScalar(u8, line, '/') != null) {
+ var start = File.rawAtDisplay(tab, line, width - (register_cut - 1));
+ if (File.rawDisplayCol(tab, line, start) < width - (register_cut - 1)) start = modal.nextGrapheme(line, start);
+ return std.mem.concat(arena, u8, &.{ "…", line[start..] });
+ }
+ return std.mem.concat(arena, u8, &.{ line[0..File.byteAtDisplay(tab, line, register_cut - 1)], "…" });
+}
/// `"`'s level: a child a register, its label the first line of its value
/// (`—` when empty), cut. Read when the level is (a key, a frame), never
@@ -553,13 +575,15 @@ test "Help's rows: every leaf of every root, spelled as its chord, its word and
for (flat) |f| try std.testing.expectEqual(f.row.len, f.lower.len);
}
-test "\" shows the registers rolled, each its first line; Down unrolls them beside the cursor's value; a register's key goes down to its verbs, Backspace back up, p pastes it" {
+test "\" shows the registers rolled, the ones holding something, each its value cut to 20 cells (a path from the left, a newline a dim ⏎); Down unrolls them all, `key value` with the name at the right, beside the cursor's value and its verbs, their keys in the key ink; a register's key goes down to its verbs, Backspace back up, p pastes it (UX D11)" {
const tagline = @import("tagline.zig");
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 });
defer p.deinit();
const pane = try p.setTestFile("one\ntwo\n");
try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true);
try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true);
+ try p.registers.put(p.gpa, 'n', "ab\ncd", 0, 1, true);
+ try p.registers.put(p.gpa, 'p', "/tmp/claude-1000/wuS/r/proj/core/Query.zig", 0, 1, true);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
@@ -573,8 +597,13 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi
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);
- try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null);
- try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null);
+ 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)).?;
+ const nl = std.mem.indexOf(u8, h.text, "ab⏎").? + 2;
+ for (h.spans) |span| {
+ if (span.lo == nl) break try std.testing.expectEqual(.dim, span.style);
+ } else return error.NoDimNewline;
// Down unrolls: a row each, the cursor on the default, its value
// beside them.
p.update(.{ .key = .{ .cp = Key.down } });
@@ -584,8 +613,37 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
var band: std.ArrayList(u8) = .empty;
for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme());
- try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" yank self.dirty = true;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" self.dirty = true;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "/ —") != null);
try std.testing.expect(std.mem.indexOf(u8, band.items, "\"\" · yank") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "p after P before R replace y into") != null);
+ // The empty register's `—` and the names in the dim ink, the verbs'
+ // letters bold in the key ink.
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ const Cells = struct {
+ fn at(l: *const pardes.Layer, word: []const u8) ?*const pardes.Cell {
+ for (0..l.rows) |row| {
+ const cells = l.cells[row * l.cols ..][0..l.cols];
+ var x: usize = 0;
+ while (x + word.len <= cells.len) : (x += 1) {
+ for (word, cells[x..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return &cells[x];
+ }
+ }
+ return null;
+ }
+ };
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, Cells.at(layer, "last search").?.style.fg);
+ const verbs = Cells.at(layer, "p after").?;
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, verbs.style.fg);
+ try std.testing.expect(verbs.style.bold);
+ for (0..layer.rows) |row| {
+ const cells = layer.cells[row * layer.cols ..][0..layer.cols];
+ for (cells, 0..) |cell, x| if (std.mem.eql(u8, cell.grapheme(), "—") and x > 2 and std.mem.eql(u8, cells[x - 3].grapheme(), "/"))
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg);
+ }
// The next row's value in full, every line of it.
p.update(.{ .key = .{ .cp = Key.down } });
_ = frame.reset(.retain_capacity);
diff --git a/core/draw.zig b/core/draw.zig
index 9f9abb58..1e53d1d0 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -934,7 +934,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
// A chord (Help's `SPC h t`): keys, at the text's weight.
if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key };
if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg };
- if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint)) style.fg = .{ .rgb = on.dim };
+ 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 = on.dim };
+ for (part.row.keys) |k| if (k == b) {
+ style.fg = .{ .rgb = chrome.roles.key };
+ style.bold = true;
+ };
if (part.row.under) style.ul = .single;
// A matched letter: the match ink, bold, on the row's own
// ground (never a ground of its own: on the cursor row's