diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/File.zig | 2 | ||||
| -rw-r--r-- | core/ansi.zig | 43 | ||||
| -rw-r--r-- | core/colors.zig | 65 | ||||
| -rw-r--r-- | core/draw.zig | 21 | ||||
| -rw-r--r-- | core/jj.zig | 194 | ||||
| -rw-r--r-- | core/surface.zig | 9 | ||||
| -rw-r--r-- | core/term/terminal.zig | 19 |
7 files changed, 143 insertions, 210 deletions
diff --git a/core/File.zig b/core/File.zig index 0f9178ac..332499b4 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2942,7 +2942,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. // A row whose first byte names a hue (syntax.ground_add, _del): its // grounds, the theme's, worked out once a frame and only for one. var grounds: ?Colors.Grounds = null; - const ink = ansi.inkOf(p.theme()); + const ink = ansi.inkOf(p); var filtered_storage: pardes.Term.Filter = undefined; const filtered: ?*pardes.Term.Filter = if (pane.tty_filter and spans.len > 0) blk: { filtered_storage = pardes.Term.filter(&ink, &p.tty_filter_palette); diff --git a/core/ansi.zig b/core/ansi.zig index e4fbf5da..3fb866fc 100644 --- a/core/ansi.zig +++ b/core/ansi.zig @@ -20,33 +20,12 @@ const Surface = pardes.Surface; const BodyWalk = @import("body_layer.zig").BodyWalk; const EditBuffer = panes.Text.EditBuffer; -/// The theme's colours as a terminal's paint takes them. -pub fn inkOf(theme: *const pardes.LegacyTheme) Term.Ink { - return .{ - .fg = theme.fg, - .bg = theme.bg, - .tag_fg = theme.tag_fg, - .tag_bg = theme.tag_bg, - .palette = theme.palette, - .base = theme.palette orelse .{ - theme.bg orelse theme.tag_bg, - theme.kw, - theme.str, - theme.num, - theme.box, - theme.sel_bg, - theme.comment, - theme.fg orelse theme.tag_fg, - theme.lineno, - theme.kw, - theme.str, - theme.num, - theme.scroll_thumb, - theme.sel_fg, - theme.tag_fg, - theme.fg orelse theme.tag_fg, - }, - }; +/// The theme's colours as a terminal's paint takes them (Chrome's: its page, +/// text, faint and sixteen); a theme that leaves them to the host (`dark`) +/// leaves them to a tty, and a window draws its own (DESIGN.md R14). +pub fn inkOf(p: *const Pardes) Term.Ink { + const c = p.chrome(); + return .{ .fg = c.page.text, .bg = c.page.ground, .dim = c.page.dim, .ansi = c.ansi, .host = c.host_page and !p.view().frontend.windowed }; } /// Its program's colours over the body's rows, through the theme's filter @@ -85,7 +64,7 @@ pub fn recolor(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw { const tz_paint = tracy.zone(@src(), "termPaint"); defer tz_paint.end(); - const ink = inkOf(p.theme()); + const ink = inkOf(p); Term.paint(state, &ink, &p.tty_filter_palette, pane.tty_filter, pane.scrolled_to, @intCast(lo), cols, cells, rows); } const filtered = pane.tty_filter; @@ -453,15 +432,15 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t } if (lo > hi) return; const styles = syntax.highlightDiffRows(arena, flat, lo, hi, true) catch return; - const tints: Colors.Grounds = .of(p.theme()); - const ink = p.theme().fg orelse p.theme().tag_fg; + const chrome = p.chrome(); const body_y = p.bodyTop(pane, r); shown = std.mem.splitScalar(u8, body, '\n'); for (views, 0..) |maybe, vr| { const line = shown.next() orelse break; const view = maybe orelse continue; const base = @intFromPtr(rows[view.row].ptr) - flat_start - lo; - const tint = if (base < styles.len) tints.forStyle(styles[base]) else null; + const lead: u8 = if (base < styles.len) styles[base] else 0; + const tint: ?Colors.Chrome.Diff = if (lead & syntax.ground_add != 0) chrome.add else if (lead & syntax.ground_del != 0) chrome.del else null; if (tint) |t| s.tint(tx, body_y + @as(u16, @intCast(vr)), tw, t.row, null); var c: usize = 0; var screen_c: usize = 0; @@ -478,7 +457,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t else if (panes.File.synStyle(p, @fromBackingInt(@intCast(style & syntax.syn_bits)))) |ss| ss else if (tint != null) - .{ .fg = ink, .bold = false } + .{ .fg = chrome.page.text, .bold = false } else null; if (paint) |ss| { diff --git a/core/colors.zig b/core/colors.zig index eefb2b67..315d1fc9 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -3,6 +3,7 @@ //! themes programme's), theme files, and switching themes at runtime. //! What a theme says is theme_schema.zig's. const pardes = @import("root.zig"); +const builtin = @import("builtin"); const schema = @import("theme_schema.zig"); pub const Theme = schema.Theme; pub const LegacyTheme = schema.LegacyTheme; @@ -85,7 +86,7 @@ pub const separator_floor: f32 = 1.5; /// the GUI's default ground, and a dark terminal's. pub const null_page: [3]u8 = .{ 18, 18, 18 }; /// The ink of a theme with none, on a dark page and on a light one. -const null_text: [3]u8 = .{ 0xcc, 0xcc, 0xcc }; +pub const null_text: [3]u8 = .{ 0xcc, 0xcc, 0xcc }; const null_text_light: [3]u8 = .{ 0x22, 0x22, 0x22 }; fn separatorOf(th: *const LegacyTheme) [3]u8 { const base = th.border orelse th.scroll_track; @@ -791,6 +792,11 @@ pub const Chrome = struct { // R10: the lanes (the accents but green and red, hue-sorted) and // churn's steps from the line numbers' ink to the deleted hue. c.lanes_len = lanesOf(.{ ansi[3], ansi[4], ansi[5], ansi[6], th.number, th.keyword }, .{ th.deleted orelse ansi[1], th.added orelse ansi[2] }, &c.lanes); + // A theme with no accent (a grey one) draws its lanes in one grey. + if (c.lanes_len == 0) { + c.lanes[0] = c.line_number; + c.lanes_len = 1; + } for (&c.heat, 1..) |*h, k| h.* = mixOklab(c.line_number, th.deleted orelse ansi[1], @as(f32, @floatFromInt(k)) / 8); return c; } @@ -2602,7 +2608,14 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { f.setPresent(.severities4, apart4 < Chrome.severity_apart); const err = lch(c.page.severity[0]); f.setPresent(.error_red, !(err[1] >= 0.08 and (err[2] <= 50 or err[2] >= 330))); - f.setPresent(.diff, @min(contrast(c.add.row, page), contrast(c.del.row, page)) < 1.1 or de(c.add.row, c.del.row) < 0.05); + // R10: each diff row 1.15:1 off the page, unless the text holds it + // nearer (never under its floor there: tokyonight_day's text, 4.9:1, + // leaves 1.11:1), and the two 0.05 apart. + const diff_floor = @min(4.5, text * 0.9); + for ([2][3]u8{ c.add.row, c.del.row }) |row| { + if (contrast(row, page) < Chrome.row_step - 0.005 and contrast(ink, row) > diff_floor + 0.05) f.insert(.diff); + } + if (de(c.add.row, c.del.row) < 0.05) f.insert(.diff); var ansi_least: f32 = 21; for (c.ansi[1..], 1..) |a, i| { ansi_least = @min(ansi_least, contrast(a, page)); @@ -2705,29 +2718,41 @@ test "every theme in the ring meets every floor pardes owns (DESIGN.md B4), nati try std.testing.expectEqual(0, wrong); } -test "the whole ring resolves in 150 ms of CPU, no theme in over 0.5 ms (Debug)" { - const io = std.testing.io; - var total: i96 = 0; - var worst: i96 = 0; +/// B9's budget, about 0.5 ms a theme and the ring in 150 ms on an idle +/// machine (Debug), in user-space instructions, which a loaded machine does +/// not move: Chrome.of retires about 7 a nanosecond here (the ring's 304 M +/// in 42 ms of an idle CPU, 2026-11-26). +const theme_instructions: u64 = 3_500_000; +const ring_instructions: u64 = 1_050_000_000; + +test "the whole ring resolves within B9's budget, about 0.5 ms a theme and 150 ms in all on an idle machine, counted in instructions (Debug)" { + if (builtin.os.tag != .linux) return error.SkipZigTest; + const linux = std.os.linux; + var attr: linux.perf_event_attr = .{ .type = .HARDWARE, .config = @intFromEnum(linux.PERF.COUNT.HW.INSTRUCTIONS), .flags = .{ .exclude_kernel = true, .exclude_hv = true } }; + const rc = linux.perf_event_open(&attr, 0, -1, -1, 0); + // No counter here (a container, perf_event_paranoid 3): nothing to count. + if (linux.errno(rc) != .SUCCESS) return error.SkipZigTest; + const fd: i32 = @intCast(rc); + defer _ = linux.close(fd); + var total: u64 = 0; + var worst: u64 = 0; var worst_at: usize = 0; for (&themes, 0..) |*th, i| { - // The least of five: a theme's own cost, not a page fault's. - var least: i96 = std.math.maxInt(i96); - for (0..5) |_| { - const start = std.Io.Clock.cpu_thread.now(io); - var c = Chrome.of(th); - std.mem.doNotOptimizeAway(&c); - least = @min(least, start.durationTo(std.Io.Clock.cpu_thread.now(io)).toNanoseconds()); - } - total += least; - if (least > worst) { - worst = least; + var before: u64 = 0; + var after: u64 = 0; + _ = linux.read(fd, std.mem.asBytes(&before), 8); + var c = Chrome.of(th); + std.mem.doNotOptimizeAway(&c); + _ = linux.read(fd, std.mem.asBytes(&after), 8); + total += after - before; + if (after - before > worst) { + worst = after - before; worst_at = i; } } - std.debug.print("ring resolved in {d} us, the slowest {s} in {d} us\n", .{ @divTrunc(total, 1000), themes[worst_at].name, @divTrunc(worst, 1000) }); - try std.testing.expect(total < 150 * std.time.ns_per_ms); - try std.testing.expect(worst <= std.time.ns_per_ms / 2); + std.debug.print("ring resolved in {d} instructions, the most {s}'s {d}\n", .{ total, themes[worst_at].name, worst }); + try std.testing.expect(total < ring_instructions); + try std.testing.expect(worst <= theme_instructions); } test "a theme file in the old names, a user's own or an older DumpThemes', and DumpThemes' now in the new names, load to the same Chrome" { diff --git a/core/draw.zig b/core/draw.zig index b666fc15..7f178bfb 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -330,11 +330,14 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { s.placements.clearRetainingCapacity(); @memset(&s.gpu_frames, null); const chrome = p.chromeTheme(); + // The window's rules and grips from the chrome (the themes programme's + // L2e; DESIGN.md R6, R11, G1'). + const resolved = p.chrome(); s.chrome = .{ .page = p.theme().bg, .fg = p.theme().fg, - .border = chrome.border, - .topbar_rule = config.gui_topbar_pane_border_rgb orelse chrome.border, + .border = resolved.rule, + .topbar_rule = config.gui_topbar_pane_border_rgb orelse resolved.rule, .tag_bg = chrome.tag_bg, .tagline_bg = chrome.tagline_bg, .tag_focus_bg = chrome.tag_active_bg, @@ -344,12 +347,14 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { .scroll_thumb = chrome.scroll_thumb, .match_tick = chrome.search_bg, .match_current = p.theme().fg orelse chrome.tag_fg, - .rule_px = p.theme().rule_px orelse 2, - .grip_border = boxBorder(p), - .grip_focus_ring = chrome.box, - .grip_dirty = boxDirty(p), - .tag_rule = p.theme().tag_rule, - .rail_px = @intCast(@min(255, @as(u32, p.theme().rail_px orelse 12) * p.settings.grip_width / 100)), + .rule_px = resolved.rule_px, + .grip_border = resolved.grip.ring, + .grip_focus_ring = resolved.grip.focus, + .grip_dirty = resolved.grip.dirty, + .grip_mode = resolved.grip.mode, + .grip_ink = resolved.grip.ink, + .tag_rule = resolved.tag_rule, + .rail_px = @intCast(@min(255, @as(u32, resolved.rail_px) * p.settings.grip_width / 100)), }; place(p, s); // Separators have their own role; a scrollbar need not frame the page. 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; diff --git a/core/surface.zig b/core/surface.zig index b78b58de..ce8898ad 100644 --- a/core/surface.zig +++ b/core/surface.zig @@ -206,9 +206,12 @@ pub const Chrome = struct { grip_focus_ring: [3]u8 = .{ 0, 0, 0 }, /// A dirty pane's button fill. grip_dirty: [3]u8 = .{ 0, 0, 0 }, - /// The rule between a pane's tag and its body; null is halfway between - /// the tag's ground and the page the shell actually draws. - tag_rule: ?[3]u8 = null, + /// A reading pane's ring (DESIGN.md G1'), and the ink on a filled + /// button. + grip_mode: [3]u8 = .{ 0, 0, 0 }, + grip_ink: [3]u8 = .{ 0, 0, 0 }, + /// The rule between a pane's tag and its body. + tag_rule: [3]u8 = .{ 0, 0, 0 }, /// The scroll column's width, button and scrollbar alike, in pixels at /// a 17px tagline (acme's 12 at its font); a pixel shell scales it. rail_px: u8 = 12, diff --git a/core/term/terminal.zig b/core/term/terminal.zig index 88eb1443..1c2310b1 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -418,10 +418,10 @@ pub const min_contrast: f64 = 1.5; /// `generate256Color` over the theme's sixteen), made again only when the /// theme's are not the ones `cache` was made of. pub fn filterPalette(cache: *FilterPalette, ink: *const Ink) *const [256][3]u8 { - const wanted: FilterPalette.Key = .{ .bg = ink.bg orelse ink.tag_bg, .fg = ink.fg orelse ink.tag_fg, .base = ink.base }; + const wanted: FilterPalette.Key = .{ .bg = ink.bg, .fg = ink.fg, .ansi = ink.ansi }; if (cache.key) |old| if (std.meta.eql(old, wanted)) return &cache.colors; var seed = GColor.default; - for (ink.base, 0..) |rgb, i| seed[i] = asGhostRgb(rgb); + for (ink.ansi, 0..) |rgb, i| seed[i] = asGhostRgb(rgb); const colors = GColor.generate256Color(seed, .empty, asGhostRgb(wanted.bg), asGhostRgb(wanted.fg), false); for (&cache.colors, colors) |*dst, src| dst.* = asTriple(src); cache.key = wanted; @@ -1333,6 +1333,12 @@ fn cellStyle(ink: *const Ink, ci: ghostty_vt.PageList.Cell, filtered: ?*Filter, }, else => {}, }; + // SGR faint on the page's text is the page's dim ink (DESIGN.md R15): + // toward the page, so as faint on a light theme as on a dark one. + if (cs.dim and std.meta.eql(cs.fg, plain.Color{ .rgb = ink.fg })) { + cs.fg = .{ .rgb = ink.dim }; + cs.dim = false; + } return cs; } @@ -1353,8 +1359,8 @@ pub fn filterOf(ink: *const Ink, palette: *FilterPalette, vt: ?*const ghostty_vt for (&source, 0..) |*rgb, i| rgb.* = t.colorForXterm(.{ .palette = @intCast(i) }) orelse rgb.*; } - var theme_bg = asGhostRgb(ink.bg orelse ink.tag_bg); - var theme_fg = asGhostRgb(ink.fg orelse ink.tag_fg); + var theme_bg = asGhostRgb(ink.bg); + var theme_fg = asGhostRgb(ink.fg); var dynamic_bg = if (vt) |t| t.colorForXterm(.{ .dynamic = .background }) else null; var dynamic_fg = if (vt) |t| t.colorForXterm(.{ .dynamic = .foreground }) else null; if (vt != null and vt.?.modes.get(.reverse_colors)) { @@ -1504,10 +1510,7 @@ fn colorDistance(a: GColor.RGB, b: GColor.RGB) u32 { fn ghostColor(ink: *const Ink, color: ghostty_vt.Style.Color, is_bg: bool) plain.Color { return switch (color) { - .none => blk: { - const t = if (is_bg) ink.bg else ink.fg; - break :blk if (t) |c| .{ .rgb = c } else .default; - }, + .none => if (ink.host) .default else .{ .rgb = if (is_bg) ink.bg else ink.fg }, .palette => |idx| ink.palColor(idx), .rgb => |rgb| .{ .rgb = .{ rgb.r, rgb.g, rgb.b } }, }; |
