summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Core.zig9
-rw-r--r--core/Pick.zig87
-rw-r--r--core/builtins.zig3
-rw-r--r--core/colors.zig15
-rw-r--r--core/root.zig1
5 files changed, 112 insertions, 3 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 6ee82370..d0011048 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -337,6 +337,11 @@ locations_cache: locations.Cache = .{},
tty_filter_palette: pardes.Term.FilterPalette = .{},
font_request_taken: bool = false,
custom_theme: ?Theme = null,
+/// The theme the window wears while a picker of them (or `:theme `)
+/// previews one, by index, and its chrome (colors.previewTheme); the
+/// session's own theme untouched under it.
+theme_preview: ?u16 = null,
+preview_chrome: ChromeTheme = colors.initial_chrome,
/// bodyChrome's: the theme it was worked out for, and it.
body_chrome: ?struct { theme: Theme, chrome: ChromeTheme } = null,
theme_file_path: config.Settings.Text(limits.host_path_cap) = .{},
@@ -525,7 +530,7 @@ pub const replica = .{
"opts", "dump_out", "dump_export",
"tape",
},
- .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
+ .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome", "theme_preview", "preview_chrome" },
// The host's handles, the state file every session of the user
// shares (and Recent read from it), this session's closed panes, and
// the files of a host with no file system of its own. (The 9P
@@ -2130,12 +2135,14 @@ fn sizes(p: *const Pardes, pane: *const Pane) bool {
}
pub fn theme(p: *const Pardes) *const Theme {
+ if (p.theme_preview) |i| return &themes[i];
if (p.custom_theme) |*custom| return custom;
return &themes[p.settings.theme];
}
/// The colours of the chrome: the theme's, set as it changes.
pub fn chromeTheme(p: *const Pardes) *const ChromeTheme {
+ if (p.theme_preview != null) return &p.preview_chrome;
return &p.chrome;
}
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);
+}
diff --git a/core/builtins.zig b/core/builtins.zig
index c7e821dd..eac52555 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -797,6 +797,9 @@ pub const Themes = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.themes_buffer, .steps = true, .commands = true };
pub fn run(c: Ctx) void {
+ // From the keyboard, where the walk is on: a picker in the tag, the
+ // window wearing its row (Pick.zig, SPEC §5.1).
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .themes, "", "", "");
panes.Output.openThemes(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "themes", err);
}
};
diff --git a/core/colors.zig b/core/colors.zig
index 84595a30..0751d8c5 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -832,6 +832,21 @@ pub fn themeIndex(name: []const u8) ?usize {
return null;
}
+/// The window wearing theme `index` (SPEC §5.1, a theme's preview), or
+/// its own again (null): nothing loaded, the session's theme and a theme
+/// file as they were; its chrome worked out once a theme, never a frame.
+/// The themes picker's (Pick.zig), and `:theme `'s argument rows'.
+pub fn previewTheme(p: *Pardes, index: ?usize) void {
+ const i = index orelse {
+ p.theme_preview = null;
+ return;
+ };
+ if (i >= themes.len) return;
+ if (p.theme_preview) |had| if (had == i) return;
+ p.theme_preview = @intCast(i);
+ p.preview_chrome = ChromeTheme.fromTheme(&themes[i]);
+}
+
pub fn setThemeIndex(p: *Pardes, index: usize) void {
if (index >= themes.len or
(p.custom_theme == null and p.theme_file_path.get().len == 0 and
diff --git a/core/root.zig b/core/root.zig
index a4adf7b1..88ae821b 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -761,6 +761,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; the terminal's own digest covers its active area, not its history (Term.zig `calls`)" },
.{ "Core.zig", "diff_output locations_cache tty_filter_palette body_chrome", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" },
.{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" },
+ .{ "Core.zig", "theme_preview preview_chrome", "a themes picker's preview (colors.previewTheme): made from the live picker's cursor, in the digest with it, after every step (Pick.produceAll) and gone at its roll-up; a step reading a theme meanwhile reads the one its own state previews" },
.{ "Core.zig", "multi_first multi_stop multi_index multi_count exec_depth exec_column", "a step's own: set by a key's replay across the ranges (normal.replaySels) and a word's run (exec.zig), each put back before the step ends; between steps what `init` makes, so a load takes them as it makes them (a dump's said 2^30 ranges once: a yank sized its register by it)" },
.{ "Core.zig", "rects col_x col_w", "a view's geometry: the layout pass's (layout.compute) over its columns and screen, at every sync and resize, and at a load (dump.afterLoad); never read before it" },
.{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" },