From e793644c7192a96ae2e39e072708b059edafaeeb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 01:30:32 -0300 Subject: jj, ansi, colors: the Changes layer and a terminal's diff draw their added and deleted rows, lanes and churn from the chrome (the themes programme's L2c; DESIGN.md R10, B6), worked out once a theme change by Chrome.of and read by `p.chrome()`, never derived again a frame, a row or a ghost line: a line a change added whole and a ghost line it added on `add.row`, a line taken away whole and a line going on `del.row`, its text in `line_number`, the words that went on `del.emph` and the words that came on `add.emph`, a description's id in the keyword's syntax ink where one change is pinned; one change pinned, its lane in the diff's own markers, `add.ink` beside a row it wrote and `del.ink` beside one it took away (the user's rulings of 2026-11-23); several, `lanes` (the sixteen's accents and the number and keyword hues, written and taken away left out, hue-sorted, R10); churn on `heat`'s eight steps from the line numbers' ink to the deleted hue, the step a count's log share of the hottest; a finished command pane's diff (ansi.recolorDiffOutput) on `add.row`/`del.row`, its markers `add.ink`/`del.ink`, its words the page's text; DELETED: jj.laneInks, laneColours and their HSV helpers (hue, hueApart, chroma, hue_apart), themeRed and its literal #cf222e and #2ea043 (the second copies of Grounds' fallbacks), heatColour's OKLab mix a row, the six Grounds.of a frame (one per ghost row, mark and going line); THE CAUSE where one moved: the old reds and greens were the palette's or two literals, so `dark` and every theme without a palette drew GitHub's red and green on rows mixed from the tag (the page's stand-in), the lane inks were pushed toward the text by 40 % steps to 3:1 on that page, and the markers on the patch view and the lanes disagreed (C1's surfaces.md §3.7); and a theme whose accents are all grey would divide by a lane count of 0 (colors: `lanes` now never empty: a theme with no accent draws its lanes in the line numbers' grey); the ring's `diff` check at B4's floor, 1.15:1 (was 1.1), unless the theme's text holds the row nearer (R10: never under its floor on the row: tokyonight_day's #3760bf on #e1e2e7, 4.9:1, leaves 1.11:1), and 0.05 apart; RUN (TEST FIRST): jj.zig's lane tests re-pinned to the chrome ("Changes draws a lane ...", "Changes draws what the text has not ...", "from the middle ...", "Churn counts ...", "Compare pins ...": the lanes `lanes[pin]`, a whole line's ground `add.row`, a going line's `del.row`, the ghost text `line_number`, the id `syntax[keyword]`, one change's lane `add.ink`/`del.ink`, churn's hottest `heat[7]` and 3-of-4's `heat[6]`), and "a diff's two lane inks in every theme" now asks every theme's markers apart and 4.5:1 on their row and words (as near as the theme reaches): on the base the four drawing tests fail (the old inks) and the ring fails tokyonight_day at 1.15, all pass now; diffview.golden re-recorded: rows 18-20 and 23-25 (the command pane's `cat change.diff`: its deleted row #302b25 -> #331a12, its added rows #263025 -> #132503: R10's rows 1.15:1 off orchard's page in the hue, where Grounds mixed the page 18 % toward the palette's colour; the markers #f1a39b and #b6ce94 unchanged, orchard's own red and green already 4.5:1 there), the diff pane's own rows (File.zig, L2b's) and diffstack.golden unchanged; GATES: core-test 1123/1296 (173 skipped; the base's count), process-test `diff` 2/2 after the update; load 3.5 to 6.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/jj.zig | 194 ++++++++++++++++++------------------------------------------ 1 file changed, 56 insertions(+), 138 deletions(-) (limited to 'core/jj.zig') diff --git a/core/jj.zig b/core/jj.zig index 63488b8c..e9b8edd1 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -1942,9 +1942,9 @@ fn ghostLanes(ch: *const Changes, ghosts: []const Ghost, gi: usize, first_row: b /// a changed line's old text grey, the words that went red; a /// description's id and title in its lane's colour `lane`, or with one /// change pinned (no one colour a lane) its id in the theme's keyword ink, -/// its author and age grey. +/// its author and age grey. All of them the chrome's (Chrome.add, .del). fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i32, from: usize, to: usize, pad: i32, marks: []const [2]u32, lane: ?[3]u8, x: u16, y: u16, w: u16) void { - const th = p.theme(); + const chrome = p.chrome(); const tab = p.settings.tab; const said = File.sourceLine(pane, row); const Ink = struct { @@ -1975,13 +1975,13 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i3 const ink: Ink = .{ .q = p, .s = s, .pane = pane, .row = row, .from = from, .to = to, .pad = pad, .x = x, .y = y, .w = w }; _ = tab; switch (g.kind) { - .deleted => s.tint(x, y, w, pardes.colors.Grounds.of(th).del.row, th.lineno), - .added => s.tint(x, y, w, pardes.colors.Grounds.of(th).add.row, null), + .deleted => s.tint(x, y, w, chrome.del.row, chrome.line_number), + .added => s.tint(x, y, w, chrome.add.row, null), .changed => { - ink.fg(0, said.len, th.lineno); + ink.fg(0, said.len, chrome.line_number); for (marks[g.marks..][0..g.nmarks]) |m| { const c = ink.cells(m[0], m[1]); - if (c[0] < c[1]) s.tint(x + c[0], y, c[1] - c[0], pardes.colors.Grounds.of(th).del.emph, null); + if (c[0] < c[1]) s.tint(x + c[0], y, c[1] - c[0], chrome.del.emph, null); } }, .description => { @@ -1989,8 +1989,8 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i3 // title) in the lane's colour, the author and the age grey. const id_end = std.mem.indexOfScalar(u8, said, ' ') orelse said.len; const author = @min(g.author, said.len); - ink.fg(0, if (lane != null) author else id_end, lane orelse th.kw); - ink.fg(author, said.len, th.lineno); + ink.fg(0, if (lane != null) author else id_end, lane orelse chrome.syntax[@intFromEnum(syntax.Syn.keyword)]); + ink.fg(author, said.len, chrome.line_number); }, } } @@ -2010,7 +2010,7 @@ fn inkCame(p: *Pardes, s: *pardes.Surface, pane: *Pane, marks: []const [2]u32, r if (lo >= hi) continue; const from = here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(lo)); const to = @min(@as(i32, w), here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(hi))); - if (from >= 0 and from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), pardes.colors.Grounds.of(p.theme()).add.emph, null); + if (from >= 0 and from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), p.chrome().add.emph, null); } } @@ -2245,82 +2245,6 @@ fn nest(lines: []Line, npins: usize) void { } } -/// A diff's two inks (one change pinned, `paintLanes`): its lane's colour -/// says the kind of the row it stands beside (the user's rulings of -/// 2026-11-23), `added` beside a row it wrote (a line added whole, a changed -/// line's new text), `taken` beside a row it took away (a line taken away, a -/// changed line's old text). -pub const Inks = struct { added: [3]u8, taken: [3]u8 }; - -/// The diff's own two colours: the theme's green and its red (the grounds' -/// and the changed words' hues), each pushed toward the ink until it reads -/// 3:1 on the page (or nearly as the ink does, where the ink reads less). -pub fn laneInks(th: *const pardes.LegacyTheme) Inks { - var inks: [2][3]u8 = .{ if (th.palette) |c| c[2] else .{ 0x2e, 0xa0, 0x43 }, themeRed(th) }; - const page = th.bg orelse th.tag_bg; - for (&inks) |*ink| { - var step: usize = 0; - while (step < 8 and pardes.colors.contrast(ink.*, page) < 3) : (step += 1) ink.* = pardes.colors.mixOklab(ink.*, th.fg orelse th.tag_fg, 0.4); - } - return .{ .added = inks[0], .taken = inks[1] }; -} - -/// The lanes' colours, a pin's the `pin % len`th, oldest first: the -/// theme's accents but the two that mean written and taken away (its green -/// and red), in hue order from the top, each a hue `hue_apart` or more from -/// the one kept before it (doom one: magenta, blue, yellow; cyan and -/// orange go). Distinct colours, never one between two. -pub fn laneColours(th: *const pardes.LegacyTheme, buf: *[8][3]u8) []const [3]u8 { - const pal = th.palette; - const grounds = [2][3]u8{ themeRed(th), if (pal) |c| c[2] else .{ 0x2e, 0xa0, 0x43 } }; - const accents: [6][3]u8 = if (pal) |c| .{ c[3], c[4], c[5], c[6], th.num, th.kw } else .{ th.kw, th.num, th.str, th.box, th.column_box orelse th.box, th.comment }; - var sorted: [6][3]u8 = undefined; - var n: usize = 0; - for (accents) |c| { - // A grey is no accent; one near written or taken away means that. - if (chroma(c) < 48 or hueApart(c, grounds[0]) < hue_apart or hueApart(c, grounds[1]) < hue_apart) continue; - sorted[n] = c; - n += 1; - } - std.sort.insertion([3]u8, sorted[0..n], {}, struct { - fn above(_: void, a: [3]u8, b: [3]u8) bool { - return hue(a) > hue(b); - } - }.above); - var kept: usize = 0; - for (sorted[0..n]) |c| { - if (kept > 0 and hueApart(c, buf[kept - 1]) < hue_apart) continue; - buf[kept] = c; - kept += 1; - } - return buf[0..kept]; -} - -/// Two hues closer than this are one colour to a lane (doom one's cyan is -/// 12 degrees from its blue, its orange 11 from its yellow). -const hue_apart = 15; - -fn chroma(c: [3]u8) u8 { - return @max(c[0], c[1], c[2]) - @min(c[0], c[1], c[2]); -} - -/// HSV's hue, in degrees. -fn hue(c: [3]u8) f32 { - const r: f32 = @floatFromInt(c[0]); - const g: f32 = @floatFromInt(c[1]); - const b: f32 = @floatFromInt(c[2]); - const hi = @max(r, g, b); - const d = hi - @min(r, g, b); - if (d == 0) return 0; - const h = if (hi == r) @mod((g - b) / d, 6) else if (hi == g) (b - r) / d + 2 else (r - g) / d + 4; - return 60 * h; -} - -fn hueApart(a: [3]u8, b: [3]u8) f32 { - const d = @abs(hue(a) - hue(b)); - return @min(d, 360 - d); -} - /// The pane's pinned changes as a view shows them, on its body's rows (body_layer.zig, while /// File.Layers.lanes is set): in the gutter's lane cells after the number a /// lane each pin whose block runs down the row, at its level, a glyph in a @@ -2333,18 +2257,13 @@ pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1 if (pane.layers.lanes > 0) paintLanes(p, s, pane, r, tx, tw, body_h); } -/// The theme's red: what a change took away; churn's top. -pub fn themeRed(th: *const pardes.LegacyTheme) [3]u8 { - return if (th.palette) |c| c[1] else .{ 0xcf, 0x22, 0x2e }; -} - -/// A count's colour on churn's gradient: smooth from the line numbers' -/// grey to the theme's red, on a log scale of the count against the -/// hottest; null for none. -fn heatColour(th: *const pardes.LegacyTheme, count: u16, hottest: u16) ?[3]u8 { +/// A count's colour on churn's eight steps from the line numbers' grey to +/// the deleted hue (Chrome.heat, worked out with the theme), on a log scale +/// of the count against the hottest; null for none. +fn heatColour(c: *const pardes.colors.Chrome, count: u16, hottest: u16) ?[3]u8 { if (count == 0 or hottest == 0) return null; const t = @log(@as(f32, @floatFromInt(count)) + 1) / @log(@as(f32, @floatFromInt(hottest)) + 1); - return pardes.colors.mixOklab(th.lineno, themeRed(th), t); + return c.heat[@min(c.heat.len, @as(usize, @intFromFloat(@ceil(t * c.heat.len)))) -| 1]; } /// The heat lane: a cell after the line number (before the changes' @@ -2362,7 +2281,7 @@ fn paintHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1 if (row < 0 or File.readOnlyRow(f, @intCast(row)) != null) continue; const line = File.fileRow(f, @intCast(row)); if (line >= heat.lines.len) continue; - const rgb = heatColour(p.theme(), heat.lines[line], heat.hottest) orelse continue; + const rgb = heatColour(p.chrome(), heat.lines[line], heat.hottest) orelse continue; var style = s.at(x, body_y + vr).style; style.fg = .{ .rgb = rgb }; s.set(x, body_y + vr, "\u{258c}", style); @@ -2380,7 +2299,7 @@ pub fn railHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, id: usize, rail: pa for (0..rail.h) |row| { const lo = row * total / rail.h; const hi = @max(lo + 1, (row + 1) * total / rail.h); - const rgb = heatColour(p.theme(), std.mem.max(u16, heat.lines[lo..@min(hi, total)]), heat.hottest) orelse continue; + const rgb = heatColour(p.chrome(), std.mem.max(u16, heat.lines[lo..@min(hi, total)]), heat.hottest) orelse continue; if (p.view().frontend.windowed) s.heat.append(p.gpa, .{ .owner = @intCast(id), .row = @intCast(row), .rgb = rgb }) catch {} else @@ -2393,18 +2312,18 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const ch = answered(p, f.layer.owner) orelse return; if (ch.lines.len == 0) return; const tab = p.settings.tab; - var buf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &buf); - if (colours.len == 0) return; - // One change pinned is a diff: its lane in the diff's own two colours, - // by the row's kind; several, a colour a change, to tell them apart. - const one: ?Inks = if (ch.pins.len == 1) laneInks(p.theme()) else null; + const chrome = p.chrome(); + const colours = chrome.lanes[0..chrome.lanes_len]; + // One change pinned is a diff: its lane in the diff's own two markers + // (the user's rulings of 2026-11-23: added beside a row it wrote, deleted + // beside one it took away); several, a colour a change, to tell them + // apart. + const one = ch.pins.len == 1; const gutter = File.gutterWidth(pane); const cells = File.laneCells(pane); if (gutter >= tw or cells == 0) return; const first = tx + gutter - cells; const windowed = p.view().frontend.windowed; - const ground = pardes.colors.Grounds.of(p.theme()).add.row; const body_y = p.bodyTop(pane, r); const nrows = File.lineCount(f.content); var vr: u16 = pane.context_rows; @@ -2424,7 +2343,7 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const next = pane.wrapAt(tab, @as(i32, vr) + 1); const to: usize = if (next.line == w.line) @intCast(next.at) else File.sourceLine(pane, w.line).len; const first_row = w.at <= 0; - inkGhost(p, s, pane, g, w.line, @intCast(@max(0, w.at)), to, w.pad, ch.marks, if (one == null) colours[g.pin % colours.len] else null, tx + gutter, y, tw - gutter); + inkGhost(p, s, pane, g, w.line, @intCast(@max(0, w.at)), to, w.pad, ch.marks, if (one) null else colours[g.pin % colours.len], tx + gutter, y, tw - gutter); if (g.kind == .description and first_row) points = @enumFromInt(g.pin); taken = g.kind == .deleted or g.kind == .changed or (g.kind == .description and takenAbove(ch.ghosts, gi)); break :ghost ghostLanes(ch, ch.ghosts, gi, first_row); @@ -2432,9 +2351,9 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const at = File.fileRow(f, row); if (at >= ch.lines.len) continue; const line = ch.lines[at]; - if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, ground, null); + if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, chrome.add.row, null); // Going: a pin ahead takes it away. - if (line.going != .none) s.tint(tx + gutter, y, tw - gutter, pardes.colors.Grounds.of(p.theme()).del.row, null); + if (line.going != .none) s.tint(tx + gutter, y, tw - gutter, chrome.del.row, null); taken = line.going != .none; if (!line.whole and line.nmarks > 0) inkCame(p, s, pane, ch.marks[line.marks..][0..line.nmarks], w.line, vr, tx + gutter, y, tw - gutter); break :line line.lanes; @@ -2442,7 +2361,7 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u for (lanes, 0..) |lane, level| { if (lane == .none) break; const arrow = lane == points; - const rgb = if (one) |d| (if (taken) d.taken else d.added) else colours[@intFromEnum(lane) % colours.len]; + const rgb = if (one) (if (taken) chrome.del.ink else chrome.add.ink) else colours[@intFromEnum(lane) % colours.len]; if (windowed) { // A body a pixel shell draws as a layer is painted on a // temporary surface first: its lanes are not drawn yet. @@ -2877,10 +2796,10 @@ test "Changes draws a lane a pinned change after the line number, nested ones a const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + before; - var buf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &buf); + const c = p.chrome(); + const colours = c.lanes[0..c.lanes_len]; try testing.expect(colours.len >= 3); - const ground = pardes.colors.Grounds.of(p.theme()).add.row; + const ground = c.add.row; // Lines 1-10, each on the row the view draws it at (ghost rows // stand between): `fn`'s spine on all; `mid` on 3-6; `shift` on 4. const want = [_][]const u8{ "0", "0", "01", "012", "01", "01", "0", "0", "0", "0" }; @@ -2917,16 +2836,15 @@ test "Changes draws a lane a pinned change after the line number, nested ones a } } -test "a diff's two lane inks in every theme: its green and its red, never one colour, each read on the page" { - for (&pardes.colors.legacy_themes) |*th| { - const inks = laneInks(th); - errdefer std.debug.print("{s}: added {any} taken {any}\n", .{ th.name, inks.added, inks.taken }); - try testing.expect(!std.meta.eql(inks.added, inks.taken)); - const page = th.bg orelse th.tag_bg; - // 3:1, or as near the theme's own ink's as it reads (hex_poison's). - const floor = @min(3, pardes.colors.contrast(th.fg orelse th.tag_fg, page)) - 0.1; - try testing.expect(pardes.colors.contrast(inks.added, page) >= floor); - try testing.expect(pardes.colors.contrast(inks.taken, page) >= floor); +test "a diff's two lane inks in every theme are its added and deleted markers (DESIGN.md R10): never one colour, each 4.5:1 on its rows, as near as the theme reaches" { + for (&pardes.colors.themes) |*th| { + const c: pardes.colors.Chrome = .of(th); + errdefer std.debug.print("{s}: added {any} deleted {any}\n", .{ th.name, c.add, c.del }); + try testing.expect(!std.meta.eql(c.add.ink, c.del.ink)); + for ([2]pardes.colors.Chrome.Diff{ c.add, c.del }) |d| for ([2][3]u8{ d.row, d.emph }) |ground| { + const reach = @max(pardes.colors.contrast(@splat(255), ground), pardes.colors.contrast(@splat(0), ground)); + try testing.expect(pardes.colors.contrast(d.ink, ground) >= @min(4.5, reach) - 0.01); + }; } } @@ -3003,9 +2921,8 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + File.gutterWidth(pane) - File.laneCells(pane); - var cbuf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &cbuf); - const grounds = pardes.colors.Grounds.of(p.theme()); + const grounds = p.chrome(); + const colours = grounds.lanes[0..grounds.lanes_len]; const lanes = [_][]const u8{ "0", "0", "02", "02", "02", "02", "01", "01", "01", "0", "0", "0" }; const Ground = enum { none, add, del }; const ground = [_]Ground{ .add, .add, .none, .none, .add, .none, .del, .del, .none, .add, .add, .none }; @@ -3048,7 +2965,7 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line try testing.expectEqual(pardes.Color{ .rgb = colours[pin] }, s.at(body.x + File.gutterWidth(pane), body.y + row).style.fg); try testing.expectEqual(pardes.Color{ .rgb = colours[pin] }, s.at(body.x + File.gutterWidth(pane) + 5, body.y + row).style.fg); } - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(body.x + File.gutterWidth(pane) + 4, body.y + 6).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = grounds.line_number }, s.at(body.x + File.gutterWidth(pane) + 4, body.y + 6).style.fg); // The changed line: on its old text the word that went (`b`) red, // on it the word that came (`b2`) green; the rest of each neither. const text_x = body.x + File.gutterWidth(pane); @@ -3071,10 +2988,9 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line const s1 = try p.render(arena.allocator()); const top = s1.region(.body, id).?.rect.y; const at = body.x + File.gutterWidth(pane) - File.laneCells(pane); - const inks = laneInks(p.theme()); - try testing.expect(!std.meta.eql(inks.added, inks.taken)); + try testing.expect(!std.meta.eql(grounds.add.ink, grounds.del.ink)); for ([_]u16{ 2, 3, 4, 5 }, [_]bool{ true, false, false, false }) |row, red| { - const ink = if (red) inks.taken else inks.added; + const ink = if (red) grounds.del.ink else grounds.add.ink; if (windowed) { var n: usize = 0; for (s1.lanes.items) |lane| if (lane.y == top + row) { @@ -3084,8 +3000,9 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line try testing.expectEqual(@as(usize, 1), n); } else try testing.expectEqual(pardes.Color{ .rgb = ink }, s1.at(at, top + row).style.fg); } - try testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, s1.at(text_x, top + 5).style.fg); - try testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.theme().kw }, s1.at(text_x + 5, top + 5).style.fg)); + const keyword = grounds.syntax[@intFromEnum(syntax.Syn.keyword)]; + try testing.expectEqual(pardes.Color{ .rgb = keyword }, s1.at(text_x, top + 5).style.fg); + try testing.expect(!std.meta.eql(pardes.Color{ .rgb = keyword }, s1.at(text_x + 5, top + 5).style.fg)); } } @@ -3299,12 +3216,12 @@ test "a description is whole, its title and its author never cut: in a pane narr const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, s.at(x, body.y + 3).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().syntax[@intFromEnum(syntax.Syn.keyword)] }, s.at(x, body.y + 3).style.fg); const last: u16 = body.y + 3 + @as(u16, @intCast(n - 1)); const end = x + @as(u16, @intCast(File.displayWidth(p.settings.tab, Ghosts.text(pane, got[3 + n - 1])))) - 1; try testing.expectEqualStrings("w", s.at(end, last).grapheme()); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(end, last).style.fg); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(end - 4, last).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().line_number }, s.at(end, last).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().line_number }, s.at(end - 4, last).style.fg); const first = x - File.laneCells(pane); for (0..n) |k| { const y = body.y + 3 + @as(u16, @intCast(k)); @@ -4068,7 +3985,7 @@ test "from the middle: in a revision's pane a pin behind it shows the lines it t const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane) + 1; - const grounds = pardes.colors.Grounds.of(p.theme()); + const grounds = p.chrome(); for ([_]u16{ 1, 8 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, s.at(x, body.y + row).style.bg); for ([_]u16{ 7, 11 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, s.at(x, body.y + row).style.bg); } @@ -4255,8 +4172,10 @@ test "Churn counts the changes that touched each declaration and draws them afte const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane) - 1; - const red = themeRed(p.theme()); - const warm = pardes.colors.mixOklab(p.theme().lineno, red, @log(3.0) / @log(4.0)); + // Churn's steps (Chrome.heat): the hottest the last, f's 3 of 4's + // log, the seventh. + const red = p.chrome().heat[7]; + const warm = p.chrome().heat[6]; for (0..7) |row| { const cell = s.at(x, body.y + @as(u16, @intCast(row))); if (row == 3) { @@ -4465,8 +4384,7 @@ test "Compare pins the whole difference between each two points as one change: t const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + File.gutterWidth(pane) - File.laneCells(pane); - var cbuf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &cbuf); + const colours = p.chrome().lanes[0..p.chrome().lanes_len]; for ([_]u16{ 3, 7, 8 }, [_]usize{ 0, 1, 1 }) |row, pin| { if (windowed) { var n: usize = 0; -- cgit v1.3 From 5dab435d7262b87d2cf40d6a27cea9c2d981c2e8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 04:01:58 -0300 Subject: Core, Term: a terminal's emulator and pty are resized once a step and its burst of inputs, at the size the layout settles on, never once a key: a level that borrows a shell's rows and gives them back in one burst resizes neither, and the shell keeps its prompt line (agent M1's find, ymkwwwnn 94f00e966c90: ttyhelp's row 3, the shell's `$`, blank after `SPC ? tutor`); THE CAUSE: Pardes.sync, at the end of every `update` (a key), resized each terminal whose rect changed (Pane.resizeGrid, Term.resize) and queued its pty's resize; `?`'s level takes 3 of the shell's rows (layout.floorRows), `tutor` in the same read gives them back, so the emulator was reflowed twice, and each reflow cleared the prompt line under its cursor for the shell to draw again (ghostty's Screen.resize, clearPromptForRedraw under Terminal.flags.shell_redraws_prompt); bash, told twice with no gap, reads its size once, finds the one it had and draws nothing (the pty probe, .scratch/walkui/T123/bashprobe.py, bash 5.3.20 with pardes's mark: resized 17 -> 14 -> 17 with no gap it writes no byte; 0.3 s apart it writes `\r\e[K\r` and its prompt twice); THE FIX: `sync` is `layOut` (the geometry, every pane's cols and rows, the bands, the greetings) and `sizeTerminals`, which gives each terminal its pane's size when its emulator has another (Term.grid's cols and len: no new state, nothing in the dump), resizes the grid and queues the pty's resize; `update` lays out only, and `settle` (a pump's, a replica's step) sizes the terminals after its queued inputs and before the effects; a 9P request's step (serveFs, a kbdin write of many keys among them), a view's open and close and a watched file's reload keep the whole `sync`; `toView` sizes them before the live view parks (a terminal is sized by one view, `sizes`); a step's own layouts in its middle (a picker's first preview, Pick's showText, showKind and putBack, Query.displayPreview, Store.reopen, jj.open, layout.givePaneRows) call `layOut`; RUN (TEST FIRST): Core.zig "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty ..." boots ttyhelp's layout in the core (100x31, a shell over the +New), gives the shell pardes's bash prompt, focuses the +New and types SPC ? t u t o r with one settle after: fails on the base (two resize_pty effects queued, the shell's first row blank after the settle), passes now; three tests that fed a new shell before any step's end sized it get a `sync` (two in Core.zig) or a `settle` (ninep/pty.zig, pty/ctl's winsize read back after a resize), Term.zig's S1 table counts Core.zig's third Term.grid; the ttyhelp golden re-recorded: row 3 is the shell's `$` again (its leaderworks snap lists 6 rows, not 7); THE MARK (the ruling's second part): ghostty's own bash integration (the genizah's, and the pinned 1.4.0's) marks bash's prompt `133;A;redraw=last;cl=line`: `last` clears only the cursor's line on a resize (bash redraws only a prompt's last line), so it would not have kept M1's one-line `$` either, and ghostty never says `redraw=0` for bash (a narrower reflow would leave the old wrapped rows under bash's redraw): the mark is unchanged (`redraw=last` would keep a multi-line PS1's first lines through a real resize: a separate change, not made); a user hit it whenever a pane beside a shell at its prompt borrowed its rows and gave them back faster than the shell read its size; NEW HOT PATHS: settle and toView walk the panes once (a terminal: Term.grid, its two sizes compared), where sync did per step before; GATES: core-test 1129/1303 (174 skipped: +1, the new test needs a terminal), shell-test 1351/1354 (3 skipped: +1), pane-test 183/184, behaviour-test 285/285 and --replay 20 seeds of 70 steps, 0 failures, process-test 1 of 147 failed (3 skipped): ttyhelp, the golden re-recorded, then 5 of 5 runs alone pass, term-test 17/17, kitty-test 45/45, the gui unit-test 1959/1963 (4 skipped: +1; its perf check's BaselineHarnessMismatch, every base's); no dump change (no new state; effects are local); no frame or perf gate (the user's rule of 2026-11-26); the shots (S kit, 26 px, .scratch/walkui/T123/png): after-0..3, this change's Debug gui: ttyhelp's bare boot, the +New clicked, `SPC ? tutor` in one pty write: the prompt stays on row 3 and the level ends on the +New's tag row as in the golden; before-0..3, the installed stage's (install74): that build's level keeps 7 of the shell's rows after `tutor` (it predates W1's floor), one shrink that bash redraws, so it does not show the fault; load 4.5 to 9.0 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 82 +++++++++++++++++++++++++++++++++++++------ core/Pick.zig | 8 ++--- core/Query.zig | 2 +- core/Store.zig | 2 +- core/Term.zig | 2 +- core/jj.zig | 2 +- core/layout.zig | 2 +- core/ninep/pty.zig | 1 + test/snapshots/ttyhelp.golden | 1 - 9 files changed, 82 insertions(+), 20 deletions(-) (limited to 'core/jj.zig') diff --git a/core/Core.zig b/core/Core.zig index cbcf4324..4c98977a 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1349,6 +1349,8 @@ pub fn toView(p: *Pardes, k: View.Id) void { if (k.index() == p.live) return; const taped = pardes.tape.enter(p, .{ .to_view = k }); defer pardes.tape.leave(p, taped); + // A terminal the going view sizes takes the size its inputs left it. + p.sizeTerminals(); Views.to(p, k.index()); } @@ -1667,6 +1669,7 @@ pub fn settle(p: *Pardes) void { // ...and the last line of an open closed with no newline after it. ctlfs.runClosedLines(p); while (p.nextQueued()) |ev| p.update(ev); + p.sizeTerminals(); while (p.nextEffect()) |e| p.perform(e); turn.bump(&turn.epoch); } @@ -1847,7 +1850,9 @@ fn updateInner(p: *Pardes, ev: Event) void { pardes.panes.Query.produceAll(p, ev == .tick, ev == .key); pardes.Pick.produceAll(p, ev == .tick); _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept }); - p.sync(); + // Laid out; its terminals are sized when the burst it came in is + // (`settle`, `sizeTerminals`). + p.layOut(); p.fsReport(); ctlfs.events.announce(p); } @@ -1969,8 +1974,41 @@ pub fn saveRecent(p: *Pardes) void { } /// Recompute geometry, push grid-size changes to each emulator and pty, -/// fire deferred greetings. +/// fire deferred greetings: a step of its own (a 9P request's, a view's). pub fn sync(p: *Pardes) void { + p.layOut(); + p.sizeTerminals(); +} + +/// Each terminal's emulator and pty at the size its pane is laid out to, +/// once a step and its burst of inputs (`settle`), never once a key: a +/// size the keys of one burst give and take back (a level borrowing a +/// shell's rows, the next key giving them back) reaches neither. Every +/// reflow clears the prompt line under the cursor for the shell to draw +/// again (ghostty's Screen.resize, `shell_redraws_prompt`), and the shell, +/// told twice, reads its size once, finds the one it had and draws +/// nothing: the prompt was gone until it next printed one. The emulator's +/// own size says what it was given; the view that sizes a terminal +/// (`sizes`) has its size. +pub fn sizeTerminals(p: *Pardes) void { + for (p.panes, 0..) |slot, id| { + const pane = slot orelse continue; + const state = pane.terminal orelse continue; + if (!p.sizes(pane)) continue; + const grid = pardes.Term.grid(state); + if (grid.cols == pane.cols and grid.len == pane.rows) continue; + pane.resizeGrid(p, pane.cols, pane.rows); + p.shell_rows.markStale(pane); // reflow moved every row + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); + pane.fs.winsize = null; + } +} + +/// The step's geometry: each pane's rect, tag rows and size (a terminal's +/// emulator and pty follow once a burst: `sizeTerminals`), its bands, and +/// the deferred greetings. What a step lays out in its middle, to read the +/// geometry after (a picker's first preview), is laid out with this. +pub fn layOut(p: *Pardes) void { const v = p.view(); while (p.unplaced.findFirstSet()) |id| { p.unplaced.unset(id); @@ -2085,14 +2123,6 @@ pub fn sync(p: *Pardes) void { if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0)) and (!pane.isTerminal() or p.sizes(pane))) { - // doc panes have no pty/emulator grid to reflow; just record - // the size so bodyText renders the right number of rows - if (pane.isTerminal()) { - pane.resizeGrid(p, cols, rows); - p.shell_rows.markStale(pane); // reflow moved every row - p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); - pane.fs.winsize = null; - } pane.cols = cols; pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; @@ -4197,6 +4227,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; try std.testing.expect(sp.isTerminal()); @@ -4263,6 +4294,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); p.update(.{ .key = .{ .cp = 'n', .alt = true } }); + p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ @@ -4308,3 +4340,33 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" test "every allocation failure during boot is a clean OutOfMemory" { try std.testing.checkAllAllocationFailures(std.testing.allocator, bootAndTearDown, .{}); } + +test "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty: its prompt line stays (M1's ttyhelp row 3)" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell's emulator + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 31, .boot = .tty }); + defer p.deinit(); + const shell = p.panes[0].?; + // bash's prompt as pardes's marks draw it (dev/Shell.zig bash_rc), + // the cursor at its input. + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + const below = p.view().cols[0].panes[1]; + p.view().active = below; + p.settle(); + const rows = shell.rows; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + const body_layer = @import("body_layer.zig"); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); + // `?`'s level takes rows of the shell's (layout.floorRows), `tutor` + // narrows it to one leaf and gives them back: keys of one burst, one + // settle after them, as a frontend takes a read of them. + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + p.update(.{ .key = .{ .cp = '?', .text = "?" } }); + try std.testing.expect(shell.rows < rows); + for ("tutor") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); + try std.testing.expectEqual(rows, shell.rows); + // Its pty told nothing: no SIGWINCH for a size it had. + while (p.nextEffect()) |e| try std.testing.expect(e != .resize_pty); + p.settle(); + try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ ")); +} diff --git a/core/Pick.zig b/core/Pick.zig index cfef2baf..9a9d0cde 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -1009,7 +1009,7 @@ fn preview(p: *Pardes, pk: *Pick) void { // laid out again before the place is put in its rows. if (!pk.previewed) { pk.previewed = true; - p.sync(); + p.layOut(); } const keyboard = p.view().active; defer p.view().active = keyboard; @@ -1060,7 +1060,7 @@ fn showText(p: *Pardes, pk: *Pick, id: usize, path_: []const u8, bytes: []u8) vo } pane.hscroll = 0; pk.previewed = true; - p.sync(); + p.layOut(); } /// Landing pane `id` showing the file at `path` through kind `k`, as a @@ -1083,7 +1083,7 @@ fn showKind(p: *Pardes, pk: *Pick, id: usize, k: u8, path: []const u8, bytes: [] Kind.close(p, pane); return showText(p, pk, id, path, line); } - p.sync(); + p.layOut(); } /// The one line a file shows while a picker previews it and none of its @@ -1154,7 +1154,7 @@ fn putBack(p: *Pardes, pk: *Pick) void { pane.body.cur_row = pk.aside_row; pane.body.cur_col = pk.aside_col; pane.body.vsel.active = false; - p.sync(); + p.layOut(); } /// The live picker rolled up (Esc, or the tag put to rest by anything): diff --git a/core/Query.zig b/core/Query.zig index fff6065c..1a420a68 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1704,7 +1704,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void pane.hscroll = 0; // another file: its own places, found below pane.places.clear(p.gpa); - p.sync(); + p.layOut(); } look.clearNavigationSelection(p, pane); if (at.line == 0 or at.line > File.nlines(p.gpa, f)) { diff --git a/core/Store.zig b/core/Store.zig index 1328af38..8a1c3987 100644 --- a/core/Store.zig +++ b/core/Store.zig @@ -223,7 +223,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool { }; p.view().active = free; if (layout.findPane(p, free)) |f| p.setActiveColumn(f.col); - p.sync(); + p.layOut(); return true; } diff --git a/core/Term.zig b/core/Term.zig index d4baf4e8..509da6d9 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -422,7 +422,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{ .{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" }, .{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest), counted when it held any (the feed's own unit, which filled it); only the session writes it to the pty (pty_write is off the tape)" }, // ---- reads by a step: in the digest ---- - .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, + .{ "grid", "Core.zig:3 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, .{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 panes.zig:2 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's; panes.zig: a view scrolls no history on the alternate screen)" }, .{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" }, .{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" }, diff --git a/core/jj.zig b/core/jj.zig index 63488b8c..bc2cea32 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -157,7 +157,7 @@ pub fn open(p: *Pardes, near: usize, path: []const u8, rev: []const u8, at: look if (replace) p.removePane(near, free) catch |err| p.reportError(.at(free), "At", err); layout.compute(p); // Sized for its place before it is centred there. - p.sync(); + p.layOut(); look.focusPaneLine(p, free, at, .center); return free; } diff --git a/core/layout.zig b/core/layout.zig index 3f6bea51..a6e6419b 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -402,7 +402,7 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { if (missing == 0) break; } setColumnWeights(p, at.col, &heights); - p.sync(); + p.layOut(); } pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 2dd7f7f3..2671467f 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -597,6 +597,7 @@ test "every pty/ctl verb, and every refusal" { try testing.expectEqual(@as(u64, "winsize 132 44\n".len), call(p, .{ .tag = 1, .op = .getattr, .node = ctl }).reply.attr.size); try testing.expect(std.mem.startsWith(u8, rd(p, Node.of(serialOf(p), .pty_status), 0, 64).bytes, " 132 44 ")); p.update(.{ .resize = .{ .cols = 76, .rows = 24 } }); + p.settle(); // the step's end: the pty takes its pane's size (Pardes.sizeTerminals) try testing.expect(pane.cols != 132); try testing.expectEqualStrings(try std.fmt.bufPrint(&said, "winsize {d} {d}\n", .{ pane.cols, pane.rows }), rd(p, ctl, 0, 64).bytes); diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index 92bb4675..5ab2e6f6 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -42,7 +42,6 @@ |29: 5 In the tag of the pane its Enter lands in from this one: this pane if it reads, else its rea |30: ✓ @p1 Help 1 message · SPC h m == snap leaderworks grid=100x31 cursor=12,21 -|3: |21: ^ Help tutor 1/1 |22: ▶ SPC h t Tutor help │ t Tutor |23: │ Open the tutor, a document to work through. -- cgit v1.3