summaryrefslogtreecommitdiff
path: root/core/bindings.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 05:32:50 -0300
committerGabriel Schneider <[email protected]>2026-11-25 05:32:51 -0300
commit038a94400d668406ed5fab9ad8c00e064365dbb1 (patch)
tree6d79bf51a9b53e290a7cbf5736516c2536432024 /core/bindings.zig
parent0e6c60d17dd5f0e48232a46096e3a7a92f8841cf (diff)
downloadpardes-038a94400d668406ed5fab9ad8c00e064365dbb1.tar.gz
pardes-038a94400d668406ed5fab9ad8c00e064365dbb1.zip
bindings, TagState, Band, draw: the registers as UX DESIGN.md D11 rules them: rolled, only the registers holding something (six of S's eleven items were `—`), each `key value` with its value in 20 cells at most (bindings.registerShown: its first line, a path cut from the left, `…proj/core/Query.zig`, where the useless end was cut before, other text from the right, `const best = rank(q…`, a newline that ends what shows said by a dim `⏎`, the value stopping there); unrolled, every register a row `key value` (the key bold in the key ink, the value in the text's, `—` for an empty one in the dim ink) with its name at the row's right end in the dim ink (Band.Row.meta), where the fixed name was at full ink and the value, the content, at 1.58:1; the doc step's verbs `p after P before R replace y into` dim with their letters bold in the key ink (Band.Row.keys; `next` gone); Band.Row.quiet, a byte range in the dim ink; TEST FIRST: bindings.zig's registers test holds D11 (fails on the parent at its rolled level, which shows `a const best = rank(q, nam… / —`): the rolled level with a path and a newline among its registers and the dim `⏎`, the unrolled rows, the empty register's `—` and the names in the dim ink, the verbs' letters bold in the key ink; core-test 1068/1238 (170 skipped)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/bindings.zig')
-rw-r--r--core/bindings.zig70
1 files changed, 64 insertions, 6 deletions
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);