summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig60
1 files changed, 57 insertions, 3 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 6026f11b..cb5f605d 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -458,7 +458,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp
/// Row `i` as the band shows it and what it points at, its text in
/// `arena`.
-const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none };
+const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" };
fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
const dir = pk.dir.slice();
@@ -526,7 +526,10 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
const f = owner.file orelse return row;
row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } };
},
- .themes => {},
+ // The theme in use says so, whichever the window wears (POLISH 12).
+ .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) {
+ row.meta = "in use";
+ },
.recent, .jumplist, .list, .grep, .all => {
const t = look.parsePathLine(text);
row.pre = @intCast(t.end);
@@ -669,7 +672,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step {
const rows = try arena.alloc(Band.Row, w.hi - w.lo);
for (rows, w.lo..) |*row, i| {
const r = try rowAt(p, pk, arena, i);
- row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) };
+ row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta };
}
out[0] = .{ .rows = rows };
return out;
@@ -1930,3 +1933,54 @@ test "n and N walk the newest list or search word, or the one Looked at (SPEC ยง
p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
try std.testing.expect(pane.places.current != null and !std.meta.eql(was, pane.places.current));
}
+
+test "the themes picker marks the theme in use: `in use` at its row's right end in the dim ink, the cursor on it when it opens, the mark staying on it while the window wears another (POLISH 12, UX A15)" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .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 was = p.settings.theme;
+ for (" tt") |c| p.update(.{ .key = .{ .cp = c } });
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at);
+ const Find = struct {
+ fn row(band: Band, text: []const u8) ?Band.Row {
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| if (std.mem.eql(u8, r.text, text)) return r;
+ return null;
+ }
+ };
+ var band = (try Band.of(p, a, pane, id)).?;
+ const worn = Find.row(band, pardes.colors.themes[was].name).?;
+ try std.testing.expectEqualStrings("in use", worn.meta);
+ try std.testing.expect(worn.on);
+ // One row says it.
+ var said: usize = 0;
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| {
+ said += @intFromBool(r.meta.len > 0);
+ };
+ try std.testing.expectEqual(@as(usize, 1), said);
+ // Drawn at the row's right end, in the dim ink of the selection it is on.
+ _ = try p.render(a);
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ const roles = &p.chromeTheme().roles;
+ const on = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ var found = false;
+ for (0..layer.rows) |row| {
+ const cells = layer.cells[row * layer.cols ..][0..layer.cols];
+ var at: usize = 0;
+ while (at + 6 <= cells.len) : (at += 1) {
+ if (!std.mem.eql(u8, cells[at].grapheme(), "i") or !std.mem.eql(u8, cells[at + 1].grapheme(), "n") or !std.mem.eql(u8, cells[at + 3].grapheme(), "u")) continue;
+ try std.testing.expectEqual(pardes.Color{ .rgb = on.dim }, cells[at].style.fg);
+ found = true;
+ }
+ }
+ try std.testing.expect(found);
+ // The window wearing the next: the mark stays on the theme in use.
+ p.update(.{ .key = .{ .cp = if (was + 1 < pardes.colors.themes.len) Key_.down else Key_.up } });
+ band = (try Band.of(p, a, pane, id)).?;
+ try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta);
+}