diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 22:46:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 22:46:35 -0300 |
| commit | 806dc79a694c9df50cf3e13e9091986ebc74cb96 (patch) | |
| tree | 04b7383d2b20ab08539a9b384beceee38168c882 /core/Pick.zig | |
| parent | 791d47a64db09f842d23b3d0b03c40951f30aae6 (diff) | |
| download | pardes-806dc79a694c9df50cf3e13e9091986ebc74cb96.tar.gz pardes-806dc79a694c9df50cf3e13e9091986ebc74cb96.zip | |
Pick: SPC t t (Themes) is a picker of the themes in the asking pane's own tag, the whole window wearing the theme under the cursor and no pane dimmed (every one flagged previewing), Enter wearing it, Esc putting the session's own back (pick-ui SPEC §5.1, §3.6, walk UI line F item 4): a source `themes` (Pick.Source; its rows the themes in their order, the cursor starting on the one worn; no reader, no acts, no other sources, no second row), its preview colors.previewTheme, the one function the `:theme ` argument rows can call too: Pardes.theme_preview over the session's theme in theme() and chromeTheme() (its chrome worked out once a theme, never a frame; nothing loaded, a ThemeFile and a custom theme untouched under it), set in the step of the key that moved the cursor (Pick.produceAll) and cleared at the roll-up; both fields on root.zig's kept_out list (derived from the picker's cursor, which the digest has); Themes from a 9P script or under `Jumps new-pane` opens +Themes as before; TEST: Pick.zig "SPC t t is a picker of the themes ..." (its host, the cursor on the worn theme, every pane previewing, Down wears the next with the session's unchanged, Esc, Enter); core-test 1027/1194 (167 skipped), 0 failed, load 8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 7913a7e0..a7a0d899 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -48,7 +48,7 @@ const Key = pardes.Key; /// declarations, the lines holding the query in every open pane (All, its /// places in each), the jump list, and rows handed over (a language /// server's answer), titled by their word. -pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list }; +pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, themes }; /// Each source's word in the tag and the leader keys of the builtin that /// opens it, its key cells (`␣ f Find`). @@ -61,6 +61,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 .all = .{ .word = "All", .keys = "" }, .jumplist = .{ .word = "Jumplist", .keys = "j" }, .list = .{ .word = "List", .keys = "l" }, + .themes = .{ .word = "Themes", .keys = "t" }, }); /// The pickers kept after they roll up, for their list words and Resume. @@ -181,6 +182,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] unroll(p, pk, query); start(p, pk); filter(p, pk); + // The themes: the cursor on the one worn (their order, the field empty). + if (source == .themes and query.len == 0 and p.custom_theme == null) p.view().tag_state.rows.at = @intCast(p.settings.theme); } /// A new picker in the ring, the oldest kept one dropped for it. @@ -217,6 +220,13 @@ fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void { const asker = p.panes[from].?; pk.owner = asker.serial; pk.made = false; + // A theme is no place: its list is the asking pane's own tag (§3.5), + // and its preview the whole window. + if (pk.source == .themes) { + pk.landing = asker.serial; + p.view().active = from; + return; + } const reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker); pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial; pk.made = reader == null; @@ -247,6 +257,8 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; pk.shown = no_row; + // The whole window previews a theme: no pane dimmed (SPEC §3.6). + if (pk.source == .themes) s.previewing = .full; if (p.paneBySerial(pk.landing)) |id| { s.previewing.set(id); const pane = p.panes[id].?; @@ -278,6 +290,9 @@ fn start(p: *Pardes, pk: *Pick) void { addRows(p, pk, out.written()); }, .list => addRows(p, pk, pk.rows), + .themes => for (pardes.colors.themes, 0..) |t, i| { + pk.names.add(p.gpa, t.name, 0, t.name.len, 0, @intCast(i)) catch return; + }, } } @@ -375,6 +390,8 @@ pub fn declsArrived(p: *Pardes, serial: u32) void { pub fn produceAll(p: *Pardes, tick: bool) void { for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { if (pk.names.busy()) pk.names.rescore(p.gpa); + // A theme's preview in the step of the key that moved to it. + if (pk.source == .themes) pardes.colors.previewTheme(p, themeAt(p, pk)); if (tick) preview(p, pk); }; } @@ -389,6 +406,14 @@ pub fn busy(p: *const Pardes) bool { // ---- the rows ---- +/// The theme the cursor of a themes picker is on. +fn themeAt(p: *const Pardes, pk: *const Pick) ?usize { + const n = pk.names.hits.items.len; + if (n == 0) return null; + const at = @min(p.view().tag_state.rows.at, n - 1); + return pk.names.cands.items[pk.names.hits.items[at].cand].ref; +} + /// The rows the list has now. pub fn count(p: *const Pardes, pk: *const Pick) usize { if (fuzzy(pk)) return pk.names.hits.items.len; @@ -492,6 +517,7 @@ 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 => {}, .recent, .jumplist, .list, .grep, .all => { const t = look.parsePathLine(text); row.pre = @intCast(t.end); @@ -534,6 +560,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n }); if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len}); if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); + // Themes have no acts and no other sources: no second row. + if (pk.source == .themes) { + try text.appendSlice(arena, " ⏎ wear it · esc"); + for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); + return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret }; + } // The second row: the spines go on through it from the key cells, // then the other sources' words, each switching to it. try text.append(arena, '\n'); @@ -553,7 +585,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word}); try text.appendSlice(arena, "|"); var first = false; - inline for (comptime std.enums.values(Source)) |src| if (src != .list) { + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .themes) { if (src != pk.source) { if (!first) try text.append(arena, ' '); first = false; @@ -697,6 +729,7 @@ fn openText(p: *Pardes, path: []const u8) ?[]u8 { /// The landing pane as the picker found it: its own text back, or the /// pane made for the picker taken away; the places it lit put out. fn restore(p: *Pardes, pk: *Pick) void { + if (pk.source == .themes) return pardes.colors.previewTheme(p, null); const id = p.paneBySerial(pk.landing) orelse return; for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); if (pk.made) { @@ -779,6 +812,18 @@ pub fn key(p: *Pardes, k: Key) void { return; } if (pk.spine == .acts) return actKey(p, pk, k); + // Themes: Enter wears the one under the cursor; the rows and the field. + if (pk.source == .themes) { + if (plain and k.cp == Key.enter) { + const at = themeAt(p, pk) orelse return; + TagState.toRest(p); + pardes.colors.setThemeIndex(p, at); + return; + } + if (s.rows.key(k, n)) return; + if (s.field.key(k)) filter(p, pk); + return; + } if (pk.spine == .edit) { if (plain and k.cp == Key.enter) return editRows(p, pk); if (plain and k.cp == Key.backspace and s.field.len == 0 or alt and k.cp == 'h') { @@ -1779,3 +1824,41 @@ test "a picker from a reading pane unrolls in that pane, its own text set aside try std.testing.expect(p.panes[id].?.file.?.output == null); try std.testing.expectEqual(npanes, paneCount(p)); } + +test "SPC t t is a picker of the themes in the asking pane's tag, the whole window wearing the row under the cursor and nothing dimmed; Esc puts the theme back, Enter wears it" { + const Key_ = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + const asker = p.view().active; + p.newScratchBelow(asker); + p.view().active = asker; + p.settings.jumps = .walk; + const themes = pardes.colors.themes; + const was = p.settings.theme; + const worn = p.theme().name; + for (" tt") |c| p.update(.{ .key = .{ .cp = c } }); + const s = &p.view().tag_state; + try std.testing.expectEqual(TagState.Kind.pick, s.kind); + try std.testing.expectEqual(Source.themes, live(p).?.source); + try std.testing.expectEqual(p.panes[asker].?.serial, s.host); + try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at); + try std.testing.expectEqual(pardes.MAX_PANES, s.previewing.count()); + // Down: the window wears the next theme, the session's unchanged. + p.update(.{ .key = .{ .cp = if (was + 1 < themes.len) Key_.down else Key_.up } }); + const shown = s.rows.at; + try std.testing.expect(std.mem.eql(u8, p.theme().name, themes[shown].name) and shown != was); + try std.testing.expectEqual(was, p.settings.theme); + // Esc: its own again. + p.update(.{ .key = .{ .cp = Key_.escape } }); + try std.testing.expectEqualStrings(worn, p.theme().name); + try std.testing.expect(p.theme_preview == null); + // Again, and Enter wears it. + for (" tt") |c| p.update(.{ .key = .{ .cp = c } }); + p.update(.{ .key = .{ .cp = if (was + 1 < themes.len) Key_.down else Key_.up } }); + p.update(.{ .key = .{ .cp = Key_.enter } }); + try std.testing.expectEqual(@as(@TypeOf(p.settings.theme), @intCast(shown)), p.settings.theme); + try std.testing.expectEqual(TagState.Kind.rest, s.kind); + try std.testing.expect(p.theme_preview == null); + try std.testing.expectEqualStrings(themes[shown].name, p.theme().name); +} |
