summaryrefslogtreecommitdiff
path: root/core/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 02:44:20 -0300
committerGabriel Schneider <[email protected]>2026-11-26 03:32:07 -0300
commit60e85abe53debc0c8dd8986b748e9c86086e0007 (patch)
treefe4771a54916638b9d85f04d561c0459f795802f /core/body_layer.zig
parent0fb5f04ad236a6ce9e22c94be2847f4fdb0735f2 (diff)
downloadpardes-60e85abe53debc0c8dd8986b748e9c86086e0007.tar.gz
pardes-60e85abe53debc0c8dd8986b748e9c86086e0007.zip
body_layer, Places, Query, Output, Tables, File, Prompt, Pick, Core: the body draws every colour from the chrome (the themes programme's L2b; DESIGN.md R7-R12, B5, B6, G7), worked out once a theme change by Chrome.of and read by `p.chrome()`, never by a theme's own fields or the old views: ONE SELECTION FAMILY (R7): the primary range, a `gw` label and a target with no number on `page.selection` in its ink, a multi-cursor head that selection reversed; every other range, a hover, a look preview, `m a`/`m i`'s region, a selecting prompt's dimmed preview and a query pane's current row on `selection_secondary` (the page halfway toward the selection in OKLab) in the text's own ink, where they were four sRGB mixes (25 % and 50 % toward a page that was `dark`'s tag) and a secondary drew `sel_fg`; the B1, B2 and B3 sweeps the chrome's `sweeps` (select, exec on the error hue, look on the added hue; acme its own), the body's and the tags' alike, where body_layer.buttonTints tinted the selection toward the keyword, string and number; HITS (R8, G7 as the designer's position): every place, a picker's landing line, a query pane's and a results pane's match on `hit` in the text's ink (was the theme's search ink), the current place and a landing line's matched span solid in the hue with the page's ink (`hit_current`, `hit_current_text`), where Roles drew a third tone step (1.9:1) that 68 themes could not show and a query pane its search ground; a search whose field is no regex dims its last places, the current on `hit` and the rest on `hit_faint` (new: the page halfway toward the hit, R7's secondary for hits; DESIGN.md is silent); SEVERITIES (R9): a message's words and detail after its line (Messages.inkOn, new: an error, a warning and a question their severity's ink on that ground, an echo, a notice and progress its dim ink), a diagnostics list's labels, a rename's struck name and its new one, each `page.severity`, where they were the theme's raw diagnostic inks or Roles' pushed ones; DIFF GROUNDS (R10): a patch's rows, changed words and faint lines (File.recolorSyntax), a pipe prompt's and a code action's ghost rows, `add` and `del` with the page's text, where colors.Grounds mixed the page 18 %, 28 % and 7 % toward the palette's green and red once a frame; THE REST: line numbers `line_number` and the caret's `line_number_current` (R12: derived where a theme has none, it was the plain number), the wrap marker the line numbers', a tree's guides (a call stack's) and their wrap pads the page's dim ink (were the info ink: a guide is meta, B5's dim row), a location the line numbers' ink, keys, `▸` and the sam fence `page.key`, context rows, a table's header and a hover's ghost lines on the plain tag's ground (its ink for the hover), a table's rules the page's rule ink (were `border orelse lineno`), the rail and thumb the chrome's, the body's page and text `page` (a theme that leaves its page to the host leaves it its text, as before), syntax `syntax`; DELETED: Core.bodyChrome and its cache (`body_chrome`: a whole Theme compared with meta.eql for every decorated row and every wrap-pad cell, C1's A7), body_layer.buttonTints and buttonInks, the Grounds recipe (colors.Grounds is the library's view on the chrome now: lib_syntax exports it, test/consumer pins its relations), Roles.hit and hit_current with hitOf and their floors, ChromeTheme's search_fg, diagnostic_info, diagnostic_hint and lineno (nothing reads them now); every value is Chrome.of's, worked out at a theme change (finishThemeInitialization, setThemeIndex, previewTheme, loadThemeFile), never a frame, a row or a cell: the one new one, `hit_faint`, is one OKLab mix there; RUN (TEST FIRST): Places.zig "places: each on the hit ground in its text's own ink, the current one solid ... the selection over it; a search whose field is no regex dims them, the rest faint" (orchard: after `/alpha`, Enter and `j`, the current place `hit_current` in `hit_current_text`, the other `hit` in the page's text; searched again, its current under the selection; with `(` the others `hit_faint`): fails on the base at its current place (Roles' 1.9:1 step under the text's ink, where the hue in the page's ink is asked; its first version, asked during the live prompt, failed there on #3c614a: the body's selection is the current place then, drawn over it as before); Query.zig "a query pane's hits are the body's ..." (a `/alpha` query pane: the row's match `hit` in the text's ink, the owner's current place solid, the current row `selection_secondary` between its places and to its end, none below): fails on the base at Query.zig (expected #917a53, found #5e4923, the search ground); body_layer.zig "the body's selections are one family (R7) ..." (`eC` in orchard: the primary on `page.selection` in its ink, the other range on `selection_secondary` in the text's ink, its head reversed, a B2 sweep held over beta on `sweeps[1]`): fails on the base at body_layer.zig (expected #24382c, found #243a2d); body_layer.zig "the body's surfaces take every colour from the chrome: none reads a theme's own fields or the old views (DESIGN.md B6)" (the source test: body_layer, Places, Query, Output, Tables, File, Prompt, Pick, jj and ansi, their code before their tests: `theme()` read for its name alone, no chromeTheme(), bodyChrome, .roles, Grounds or LegacyTheme); re-pinned to the chrome and failing on the base: Prompt.zig's pipe ghosts (del.row #331a12, was Grounds' #302b25) and `/`'s `▸` (page.key #add38a, was Roles' #bada9d), Pick.zig's code action ghosts and its landing line, body_layer's motion targets, the build error's `✗` in `page.severity[0]`; colors.zig "line numbers stay quiet ..." (a ThemeFile with no current number: R12's derived one, 4.5:1), look.zig's hover preview on `selection_secondary`, test/output.zig and test/panes.zig's results colours (hit, page text, line numbers, the warning severity); GOLDENS re-recorded (13, orchard unless said), each class read: (1) R8 hit ink: a match on #5e4923 (orchard's own search ground, kept as its `hit`) in the text #e5eee5 where its search ink #f7e4a5 was: callstack 6 cells, psearch 15, stepgrain 26, lsprelpath 11; (2) G7 current hit: lsprelpath row 20, the owner's current place in a query row, #0d1410 on #917a53 (the hue held 4.5:1) where it was #f7e4a5 on #5e4923, 9 cells; (3) R7 secondary: #243a2d (sRGB half) to #24382c (OKLab half), the text's own ink where `sel_fg` #f5f7ee was: multicursor 2 cells and selregex 24 (secondary ranges), stepgrain 285 and lsprelpath 185 (a query pane's current row); (4) R10 diff grounds: diffview rows 12-19 (the diff pane's own rows: added #263025 to #132503, deleted #302b25 to #331a12, 558 cells; the same values the command pane's diff took in L2c), diffstack rows 26-29 (a faint added line #171f18 to #101c0b, changed words #364131 to #203900 and #453832 to #53251b), pagercolor rows 36-37 (a +Pager's faint lines: #1a1d18 to #211812, #171f18 to #101c0b); markers and syntax inks unchanged; (5) a tree's guides: callstack rows 11-21, #92d1de (the info ink) to #666f68 (the page's dim ink), 35 cells; (6) key ink: fsearch's `▸`, #bada9d (pushed over seven tag grounds) to #add38a (the accent held on the page); (7) R7 exec sweep: headersweep and headersweep-restored, a B2 sweep on the header, #f5f7ee on #5b7e5a (the selection tinted toward the string) to #e5eee5 on #4c251b (the error hue a selection step off the page), 8 and 16 cells (draw.zig's sweeps, moved with buttonTints); (8) R12: themesel row 26, the caret line's number in solarized_dark (#586e75 to #7f9193) and acme (#999980 to #74746a), themes with no current-line number of their own; no text moved, no other golden; GATES: core-test 1132/1305 (173 skipped; the merge's 1128/1301 + 4), shell-test 1353/1356 (3 skipped), pane-test 184/185 (1 skipped), behaviour-test 280/280 and --replay 20 seeds of 70 steps, 0 failures, process-test 0 of 147 failed (3 skipped; 13 re-recorded above, ttyhelp unmoved), term-test 17/17, kitty-test 45/45; gui unit-test 1957/1961 (4 skipped; its one failure the known BaselineHarnessMismatch; test/consumer's Grounds relations pass on the chrome's rows); PICTURES (the S kit, 26 px, 100x30, `Jumps walk`; before = install74's pardes-gui, after = this tree's Debug gui): .scratch/themes/L2b/png/, `<state>-<theme>-before|after.png` and `pair-<state>-<theme>.png` side by side, in dark, neonotte84, orchard and acme: `search` (a live `/words`: the current place is the body's selection, as before), `landed` (Enter, then `j`: the current place the solid chip), `selhit` (`x` over a hit), `grep` (SPC f g count: the preview's landing line and matched span), `error` (`:zig build`'s error words after report.zig's line 11: dark's were its grey text, red now), `diff` (a .diff file's rows); the dump and the digest unchanged (`body_chrome` was derived, `theme_chrome` local), so no fuzz or soak; load 3.2 to 9.7
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/body_layer.zig')
-rw-r--r--core/body_layer.zig220
1 files changed, 137 insertions, 83 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 513f9a6d..1eb3bf54 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -148,21 +148,12 @@ pub fn paintPointerSelection(
}
}
-/// The selection colour of each pointer button's sweep: the select button's
-/// and the look and exec buttons', each tinted toward its own accent.
-pub fn buttonTints(th: *const colors.LegacyTheme) [3][3]u8 {
- if (th.sweep_bg) |own| return own;
- const accent2 = if (std.mem.eql(u8, &th.num, &th.str)) th.comment else th.num;
- return .{
- colors.mix(th.sel_bg, colors.mix(th.sel_bg, th.kw)),
- colors.mix(th.sel_bg, colors.mix(th.sel_bg, th.str)),
- colors.mix(th.sel_bg, colors.mix(th.sel_bg, accent2)),
- };
-}
-
-/// The ink over each button's sweep.
-pub fn buttonInks(th: *const colors.LegacyTheme) [3][3]u8 {
- return th.sweep_fg orelse @splat(th.sel_fg);
+/// The rail's column in the theme's rail and thumb, and the column right
+/// of it the page.
+fn paintRail(c: *const colors.Chrome, s: *Surface, bar: pardes.Region) void {
+ s.fill(bar.rect.x, bar.rect.y, 1, bar.rect.h, .{ .bg = .{ .rgb = c.rail } });
+ s.fill(bar.rect.x + 1, bar.rect.y, 1, bar.rect.h, .{ .bg = if (c.host_page) .default else .{ .rgb = c.page.ground } });
+ s.fill(bar.rect.x, bar.rect.y + bar.thumb_y, 1, bar.thumb_h, .{ .bg = .{ .rgb = c.rail_thumb } });
}
/// A pane's body, painted once. A file body with compact tree-sitter
@@ -221,14 +212,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
if (layer.cursor) |cursor| if (cursor.y < viewport_rows) {
s.cursor = .{ .x = body.rect.x + cursor.x, .y = body.rect.y + cursor.y, .bar = cursor.bar };
};
- const chrome = p.chromeTheme();
- const theme = p.theme();
- const pane_bg: Color = if (theme.bg) |c| .{ .rgb = c } else .default;
- if (rail.rect.h > 0) {
- s.fill(rail.rect.x, rail.rect.y, 1, rail.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } });
- s.fill(rail.rect.x + 1, rail.rect.y, 1, rail.rect.h, .{ .bg = pane_bg });
- s.fill(rail.rect.x, rail.rect.y + rail.thumb_y, 1, rail.thumb_h, .{ .bg = .{ .rgb = chrome.scroll_thumb } });
- }
+ if (rail.rect.h > 0) paintRail(p.chrome(), s, rail);
}
fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16, active: bool) void {
@@ -239,12 +223,13 @@ fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw:
const cur_line: i32 = if (active and typing_body) gcrow else std.math.minInt(i32);
// the body's first row, the way renderPane derives it
const body_y = p.bodyTop(pane, r);
- const context_bg = p.theme().tag_bg;
+ const chrome = p.chrome();
+ // The context rows on the tag's ground, as a header.
for (0..@min(pane.context_rows, body_h)) |context_row| {
for (0..tw) |col| {
const cell = s.at(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(context_row)));
cell.default = false;
- cell.style.bg = .{ .rgb = context_bg };
+ cell.style.bg = .{ .rgb = chrome.tag[0].ground };
cell.style.font_role = .tagline;
}
}
@@ -259,10 +244,7 @@ fn drawGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw:
while (c < prefix_width and c < tw) : (c += 1) {
const cell = s.at(tx + c, body_y + vr);
cell.default = false; // paints blank gutter rows too
- cell.style.fg = .{ .rgb = if (on_cursor)
- p.theme().lineno_active orelse p.theme().lineno
- else
- p.theme().lineno };
+ cell.style.fg = .{ .rgb = if (on_cursor) chrome.line_number_current else chrome.line_number };
cell.style.bold = on_cursor;
}
}
@@ -280,7 +262,7 @@ fn drawWrapMarkers(
) void {
if (tw <= panes.File.gutterWidth(pane) + 1) return;
const body_y = p.bodyTop(pane, r);
- const marker_fg = p.chromeTheme().lineno;
+ const marker_fg = p.chrome().line_number;
var row: u16 = 0;
while (row + 1 < pane.wrap_n and row + 1 < body_h) : (row += 1) {
if (pane.wrap_line[row + 1] != pane.wrap_line[row] or pane.wrap_col[row] < 0) continue;
@@ -292,21 +274,20 @@ fn drawWrapMarkers(
}
pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rail: ?pardes.Region) !void {
- const th = p.theme();
- const chrome = p.chromeTheme();
+ const c = p.chrome();
const tx = r.x + config.GUTTER;
const tw = r.w - config.GUTTER;
// Below the notice bands: they are stacked at the top of the body the
// way tree-sitter context rows are, so the body starts under them
// rather than being painted over by them.
const body_y = p.bodyTop(pane, r);
- const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default;
- const page_rgb = th.bg orelse th.tag_bg;
+ // A theme that leaves its page to the host leaves it its text too.
+ const pane_bg: Color = if (c.host_page) .default else .{ .rgb = c.page.ground };
// body: emulator rows, prompt rows hidden outside tty mode
const body_h = r.h -| pane.tag_rows;
const body_bottom = r.h;
const body_style: CellStyle = .{
- .fg = if (th.fg) |c| .{ .rgb = c } else .default,
+ .fg = if (c.host_page) .default else .{ .rgb = c.page.text },
.bg = pane_bg,
};
const tz_body = tracy.zone(@src(), "bodyText");
@@ -319,7 +300,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// the rows, which paint over it.
const sweep = pane.sel[pardes.sel_slot];
if (sweep.state != .none and (sweep.state != .done or pardes.sel_slot == 0) and @min(sweep.r0, sweep.r1) < pane.tag_rows)
- paintPointerSelection(p, s, pane, r, sweep, pane.tag_rows, th.sel_bg, th.sel_fg);
+ paintPointerSelection(p, s, pane, r, sweep, pane.tag_rows, c.sweeps[pardes.sel_slot].ground, c.sweeps[pardes.sel_slot].text);
{
// The rows themselves. `bodyText` above is only the string BUILD;
// this is what writes it into the surface.
@@ -363,16 +344,14 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
tz_color.end();
if (pane.isTerminal()) ansi.images(p, s, pane, id, tx, tw, body_y, body_h);
- const sel_btn = buttonTints(th);
if (p.look_hover_preview) |preview| {
if (preview.pane == id and preview.serial == pane.serial) {
// Preserve body ink, then let every real user selection below
// win over this quiet affordance.
- const preview_bg = colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg));
if (preview.file_word) |word|
- panes.File.paintWordSelection(p, s, pane, r, word.row, word.lo, word.hi, preview_bg)
+ panes.File.paintWordSelection(p, s, pane, r, word.row, word.lo, word.hi, c.selection_secondary, null)
else if (preview.sel) |sel|
- paintPointerSelection(p, s, pane, r, sel, pane.tag_rows, preview_bg, null);
+ paintPointerSelection(p, s, pane, r, sel, pane.tag_rows, c.selection_secondary, null);
}
}
const modal_hover = if (p.look_hover_preview) |preview|
@@ -385,7 +364,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// A select sweep over the tag is the tag's selection, painted there
// in the tag's own selection colours.
if (b == pardes.sel_slot and @min(sl.r0, sl.r1) < pane.tag_rows) continue;
- paintPointerSelection(p, s, pane, r, sl, pane.tag_rows, sel_btn[b], buttonInks(th)[b]);
+ paintPointerSelection(p, s, pane, r, sl, pane.tag_rows, c.sweeps[b].ground, c.sweeps[b].text);
}
// A selecting prompt's live result (Prompt.zig), dimmed while its
// field is no regex.
@@ -408,12 +387,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
} else pane.body.sels[si];
const bnd = edit.cellBounds(sr);
const hover_only = primary and modal_hover and pane.body.mode != .normal and !preview;
- const bg = if (hover_only or (selecting != null and selecting.?.dim))
- colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg))
- else if (primary)
- th.sel_bg
- else
- colors.mix(th.sel_bg, page_rgb);
+ // The primary on the selection in its ink; every other range,
+ // a hover and a dimmed preview on its faint half, the text's
+ // own ink kept (R7).
+ const full = primary and !hover_only and !(selecting != null and selecting.?.dim);
+ const bg = if (full) c.page.selection.ground else c.selection_secondary;
var vr: i32 = 0;
while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) {
const w = pane.wrapAt(p.settings.tab, vr);
@@ -452,7 +430,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
@as(i32, tw) - 1;
const col: i32 = @max(cstart, vpfx);
const end = @min(cend + 1, tw);
- if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, if (hover_only) null else th.sel_fg);
+ if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, if (full) c.page.selection.text else null);
}
if (primary and !preview and !hover_only) continue; // the hardware cursor IS the primary's
if (hover_only) continue; // quiet preview preserves the source ink
@@ -473,8 +451,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
if (crow >= pane.tag_rows and crow < @as(i32, body_bottom) and ccol >= vpfx and ccol < tw) {
const cell = s.at(tx + @as(u16, @intCast(ccol)), body_y + @as(u16, @intCast(crow - pane.tag_rows)));
cell.default = false;
- cell.style.bg = .{ .rgb = th.sel_fg };
- cell.style.fg = .{ .rgb = th.sel_bg };
+ cell.style.bg = .{ .rgb = c.page.selection.text };
+ cell.style.fg = .{ .rgb = c.page.selection.ground };
}
}
}
@@ -492,7 +470,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
if (pane.jump.items.len > 0) labels: {
const flat = edit.flatSurface(p.editor(), &pane.body) catch break :labels;
const letters = config.jump_label_alphabet;
- const style: CellStyle = .{ .fg = .{ .rgb = th.sel_fg }, .bg = .{ .rgb = th.sel_bg }, .bold = true };
+ const style: CellStyle = .{ .fg = .{ .rgb = c.page.selection.text }, .bg = .{ .rgb = c.page.selection.ground }, .bold = true };
for (pane.jump.items, 0..) |word, i| {
if (pane.jump_first) |first| if (i / letters.len != first) continue;
var at = @min(word.anchor, word.head);
@@ -563,14 +541,10 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
if (pane.file != null) try pardes.Prompt.ghosts(p, s, arena, pane, r, body_h);
// A code action's edit, previewed (Pick.zig).
if (pane.file != null) try pardes.Pick.ghosts(p, s, arena, pane, r, body_h);
- if (rail) |bar| if (bar.rect.h > 0) {
- // The rail covers the notice bands too: nothing else paints those
- // two gutter columns, so a gap there keeps the frame-wide border
- // fill and reads as a notch cut out of the scrollbar.
- s.fill(bar.rect.x, bar.rect.y, 1, bar.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } });
- s.fill(bar.rect.x + 1, bar.rect.y, 1, bar.rect.h, .{ .bg = pane_bg });
- s.fill(bar.rect.x, bar.rect.y + bar.thumb_y, 1, bar.thumb_h, .{ .bg = .{ .rgb = chrome.scroll_thumb } });
- };
+ // The rail covers the notice bands too: nothing else paints those two
+ // gutter columns, so a gap there keeps the frame-wide border fill and
+ // reads as a notch cut out of the scrollbar.
+ if (rail) |bar| if (bar.rect.h > 0) paintRail(c, s, bar);
}
/// A message at the lines it names, drawn and never written (SPEC §10.2,
@@ -585,9 +559,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
const Messages = pardes.Messages;
const f = pane.file.?;
- const chrome = p.chromeTheme();
- const th = p.theme();
- const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default;
+ const page = &p.chrome().page;
+ const pane_bg: Color = if (p.chrome().host_page) .default else .{ .rgb = page.ground };
const Hit = struct { line: usize, said: *const Messages.Said, place: *const Messages.Place };
var hits: [Messages.max_live * Messages.Said.max_places]Hit = undefined;
var n: usize = 0;
@@ -615,7 +588,7 @@ fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y:
if (at < tw) {
var buf: [160]u8 = undefined;
const words = std.fmt.bufPrint(&buf, "{s} {s}", .{ hit.said.kind.glyph(), hit.place.text.slice() }) catch &buf;
- _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.ink(chrome, hit.said.kind) }, .bg = pane_bg });
+ _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.inkOn(page, hit.said.kind) }, .bg = pane_bg });
}
if (pane.ghost_rows > 0 and row == pane.ghost_at) detail = hit.said;
}
@@ -634,7 +607,7 @@ fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y:
for (said.detail[0..k], 0..) |*text, i| {
const y = body_y + under_row + 1 + @as(u16, @intCast(i));
s.fill(tx, y, tw, 1, .{ .bg = pane_bg });
- if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.ink(chrome, said.kind) }, .bg = pane_bg });
+ if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.inkOn(page, said.kind) }, .bg = pane_bg });
}
}
@@ -682,7 +655,7 @@ fn drawnRow(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize) !?[]con
/// number (the one a prompt's current place has, Prompt.paintGutter), on
/// each row it wraps onto.
fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, body_h: u16, line: usize) void {
- const roles = &p.chromeTheme().roles;
+ const c = p.chrome();
const gutter = File.gutterWidth(pane);
const number = gutter -| File.laneCells(pane) -| pane.layers.heat -| 1;
const body_y = p.bodyTop(pane, r);
@@ -693,18 +666,19 @@ fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16,
for (gutter..tw) |x| {
const cell = s.at(tx + @as(u16, @intCast(x)), body_y + vr);
cell.default = false;
- cell.style.bg = .{ .rgb = roles.hit };
+ cell.style.bg = .{ .rgb = c.hit };
}
if (gutter > 0 and w.at == 0) {
var style = s.at(tx + number, body_y + vr).style;
- style.fg = .{ .rgb = roles.key };
+ style.fg = .{ .rgb = c.page.key };
s.set(tx + number, body_y + vr, "▸", style);
}
}
}
-/// The landing line's matched span (a Grep's match at the row's column) on
-/// the current hit's ground, over the places lit on it (UX D7).
+/// The landing line's matched span (a Grep's match at the row's column) as
+/// the current hit, solid in the hue with the page's ink, over the places
+/// lit on it (UX D7, R8).
fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void {
if (!pane.places.shows(pane)) return;
const hits = pane.places.hits.items;
@@ -713,7 +687,7 @@ fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.Fil
var i = panes.Places.firstFrom(hits, ls);
while (i < hits.len and hits[i].start <= caret) : (i += 1) {
if (hits[i].end <= caret) continue;
- File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chromeTheme().roles.hit_current);
+ File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chrome().hit_current, p.chrome().hit_current_text);
return;
}
}
@@ -768,9 +742,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
.hi = if (line == last) to - lineStart(f, line) else File.sourceLine(pane, @intCast(line)).len,
.to_edge = line != last,
};
- const th = p.theme();
- const page = th.bg orelse th.tag_bg;
- paintSourceSelection(p, s, pane, r, rows, colors.mix(page, colors.mix(page, th.sel_bg)), null);
+ paintSourceSelection(p, s, pane, r, rows, p.chrome().selection_secondary, null);
return;
}
if (cur.root != .goto and cur.root != .next and cur.root != .prev) return;
@@ -796,7 +768,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// row's keys, as many as they hold, right-aligned to its last digit,
// bold in the key ink on the gutter's ground. With no numbers, over
// the line's first cells on the selection's ground. Never a shift.
- const ink = p.chromeTheme().roles.key;
+ const ink = p.chrome().page.key;
const number = File.gutterWidth(pane) -| File.laneCells(pane) -| pane.layers.heat -| 1;
const cells = @min(if (number > 0) number else tw, tw);
for (rows[0..n], 0..) |row, i| {
@@ -811,7 +783,7 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
for (rows[i..n], keys[i..n]) |other, key| {
if (other != row) continue;
if (x >= (if (number > 0) cells else shown)) break;
- const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.theme().sel_bg };
+ const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.chrome().page.selection.ground };
s.set(tx + x, y, bindings.keyName(key), .{ .fg = .{ .rgb = ink }, .bg = bg, .bold = true });
x += 1;
}
@@ -844,13 +816,14 @@ fn hoverGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u
const from = @as(usize, body_y + dst - k) * s.cols + tx;
@memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]);
}
- const th = p.theme();
- const style: CellStyle = .{ .fg = .{ .rgb = th.tag_fg }, .bg = .{ .rgb = th.tag_bg } };
+ // On the tag's ground in its ink, as a header.
+ const tag = &p.chrome().tag[0];
+ const style: CellStyle = .{ .fg = .{ .rgb = tag.text }, .bg = .{ .rgb = tag.ground } };
const gutter: u16 = File.gutterWidth(pane);
var lines = std.mem.splitScalar(u8, text, '\n');
for (0..k) |i| {
const y = body_y + at + 1 + @as(u16, @intCast(i));
- s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = th.tag_bg } });
+ s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = tag.ground } });
if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, lines.next() orelse "", style);
}
}
@@ -865,9 +838,8 @@ fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y:
const old = @import("lsp/Ask.zig").renamedWord(pane) orelse return;
const new = p.view().tag_state.field.text();
const tab = p.settings.tab;
- const chrome = p.chromeTheme();
- const th = p.theme();
- const added: CellStyle = .{ .fg = .{ .rgb = chrome.diagnostic_hint }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true };
+ const chrome = p.chrome();
+ const added: CellStyle = .{ .fg = .{ .rgb = chrome.page.severity[3] }, .bg = if (chrome.host_page) .default else .{ .rgb = chrome.page.ground }, .bold = true };
const wide: u16 = @intCast(@min(File.displayWidth(tab, new), tw));
const gutter: i32 = File.gutterWidth(pane);
var row: u16 = pane.context_rows;
@@ -894,7 +866,7 @@ fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y:
while (c < c1) : (c += 1) {
const cell = s.at(tx + c, y);
cell.style.strikethrough = true;
- cell.style.fg = .{ .rgb = chrome.diagnostic_error };
+ cell.style.fg = .{ .rgb = chrome.page.severity[0] };
}
const x: u16 = @intCast(c1);
if (x + wide < tw) {
@@ -1193,6 +1165,12 @@ test "a build error is said where its cause is: the mark on its file's tag, its
// elsewhere.
try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected 2 argument(s), found 3") != null);
try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
+ // In the error's ink on the page (R9).
+ const mark = for (0..body.w) |i| {
+ const cell = s.at(body.x + @as(u16, @intCast(i)), body.y + 2);
+ if (std.mem.eql(u8, cell.grapheme(), "\u{2717}")) break cell;
+ } else return error.TestUnexpectedResult;
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.severity[0] }, mark.style.fg);
// The caret on line 3 and its detail asked for (K, UX D13): under the
// line, the rows below two rows down.
pane.body.cur_row = 2;
@@ -1312,7 +1290,7 @@ test "a motion root's level paints its targets in place of their lines' numbers,
try std.testing.expectEqualStrings("p", Field.of(s, gutter, body.y + 4, number, &buf));
const key = s.at(gutter + number - 1, body.y + 4);
try std.testing.expectEqualStrings("p", key.grapheme());
- try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.key }, key.style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().page.key }, key.style.fg);
try std.testing.expect(key.style.bold);
try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 5, number, &buf), 'g') != null);
try std.testing.expect(std.mem.indexOfAny(u8, Field.of(s, gutter, body.y + 5, number, &buf), "0123456789") == null);
@@ -1417,3 +1395,79 @@ test "a message's detail unrolls only on request (UX D13): the caret passing its
p.update(.{ .key = .{ .cp = 'K' } });
try std.testing.expectEqual(pardes.TagState.Kind.prompt, p.view().tag_state.kind);
}
+
+test "the body's selections are one family (R7): the primary on the selection in its ink, another range on its faint half in the text's own ink, its head the selection reversed, a B2 sweep on the chrome's exec sweep" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
+ defer p.deinit();
+ colors.setThemeIndex(p, colors.themeIndex("orchard").?);
+ const pane = try p.setTestFile("alpha beta\ngamma delta\n");
+ const id = p.view().active;
+ pane.focus = .body;
+ // `e` selects alpha, `C` copies it below: gamma the primary.
+ for ("eC") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
+ try std.testing.expect(pane.body.vsel.active and pane.body.nsel == 1);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const c = p.chrome();
+ const r = p.view().rects[id];
+ const x = r.x + config.GUTTER + panes.File.gutterWidth(pane);
+ const y = p.bodyTop(pane, r);
+ var s = try p.render(frame.allocator());
+ for (0..5) |i| {
+ const primary = s.at(x + @as(u16, @intCast(i)), y + 1).style;
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, primary.bg);
+ if (i < 4) try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.text }, primary.fg);
+ const other = s.at(x + @as(u16, @intCast(i)), y).style;
+ if (i < 4) {
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, other.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg);
+ } else {
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.text }, other.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, other.fg);
+ }
+ }
+ // B2 swept over beta, not let go: the exec sweep.
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = x + 6, .row = y } });
+ p.update(.{ .mouse = .{ .button = .middle, .kind = .drag, .col = x + 9, .row = y } });
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ for (6..10) |i| {
+ const swept = s.at(x + @as(u16, @intCast(i)), y).style;
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.sweeps[1].ground }, swept.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.sweeps[1].text }, swept.fg);
+ }
+}
+
+test "the body's surfaces take every colour from the chrome: none reads a theme's own fields or the old views (DESIGN.md B6)" {
+ const sources = [_]struct { []const u8, []const u8 }{
+ .{ "body_layer.zig", @embedFile("body_layer.zig") },
+ .{ "Places.zig", @embedFile("Places.zig") },
+ .{ "Query.zig", @embedFile("Query.zig") },
+ .{ "Output.zig", @embedFile("Output.zig") },
+ .{ "Tables.zig", @embedFile("Tables.zig") },
+ .{ "File.zig", @embedFile("File.zig") },
+ .{ "Prompt.zig", @embedFile("Prompt.zig") },
+ .{ "Pick.zig", @embedFile("Pick.zig") },
+ .{ "jj.zig", @embedFile("jj.zig") },
+ .{ "ansi.zig", @embedFile("ansi.zig") },
+ };
+ var wrong: usize = 0;
+ for (sources) |source| {
+ const name, const text = source;
+ // The code, not its tests.
+ const code = text[0 .. std.mem.indexOf(u8, text, "\ntest \"") orelse text.len];
+ // A theme is read for its name alone.
+ var at: usize = 0;
+ while (std.mem.indexOfPos(u8, code, at, "theme()")) |i| : (at = i + 1) {
+ if (std.mem.startsWith(u8, code[i + "theme()".len ..], ".name")) continue;
+ std.debug.print("{s}: a theme's own colours read at byte {d}\n", .{ name, i });
+ wrong += 1;
+ }
+ for ([_][]const u8{ "chromeTheme()", "bodyChrome", ".roles", "Grounds", "LegacyTheme" }) |old| if (std.mem.indexOf(u8, code, old)) |i| {
+ std.debug.print("{s}: `{s}` at byte {d}\n", .{ name, old, i });
+ wrong += 1;
+ };
+ }
+ try std.testing.expectEqual(@as(usize, 0), wrong);
+}