╭ changed ──╮ │src/web.zig│ ╰───────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2064 const bg = cell.style.bg; │ │2065 const inverted = !covered_by_scroll and cell.style.inverted; │ │2066 │ │2067 - if (first or cell_id != cur_id or !colorEql(fg, cur_fg) or !colorEql(bg, cur_bg) or inverted != cur_inverted) { │ │2067 + if (first or cell_id != cur_id or !std.meta.eql(fg, cur_fg) or !std.meta.eql(bg, cur_bg) or inverted != cur_inverted) {│ │2068 if (open_tag) |t| try output.appendSlice(allocator, t.closeTag()); │ │2069 │ │2070 var new_tag: ?CellTag = null; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2289 } │ │2290 } │ │2291 │ │2292 -fn colorEql(a: ?Grid.Color, b: ?Grid.Color) bool { │ │2293 - if (a) |av| return if (b) |bv| av.eql(bv) else false; │ │2294 - return b == null; │ │2295 -} │ │2296 - │ │2292 // the 16 ansi colors as the browser shows them (xterm's defaults) │ │2293 const ansi_palette = [16]Grid.Color.Rgb{ │ │2294 .{ .r = 0x00, .g = 0x00, .b = 0x00 }, .{ .r = 0xcd, .g = 0x00, .b = 0x00 }, .{ .r = 0x00, .g = 0xcd, .b = 0x00 }, .{ .r = 0xcd, .g = 0xcd, .b = 0x00 },│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2325 const prefix = " style=\""; │ │2326 @memcpy(buf[0..prefix.len], prefix); │ │2327 var i: usize = prefix.len; │ │2333 - const text = if (inverted) bg else fg; │ │2334 - const back = if (inverted) fg else bg; │ │2335 - if (text) |c| { │ │2336 - const v = colorRgb(c); │ │2337 - const s = std.fmt.bufPrint(buf[i..], "color:#{x:0>2}{x:0>2}{x:0>2};", .{ v.r, v.g, v.b }) catch return buf[0..0]; │ │2338 - i += s.len; │ │2339 - } else if (inverted) { │ │2340 - const s = std.fmt.bufPrint(buf[i..], "color:var(--bg);", .{}) catch return buf[0..0]; │ │2341 - i += s.len; │ │2342 - } │ │2343 - if (back) |c| { │ │2344 - const v = colorRgb(c); │ │2345 - const s = std.fmt.bufPrint(buf[i..], "background-color:#{x:0>2}{x:0>2}{x:0>2};", .{ v.r, v.g, v.b }) catch return buf[0..0];│ │2346 - i += s.len; │ │2347 - } else if (inverted) { │ │2348 - const s = std.fmt.bufPrint(buf[i..], "background-color:var(--fg);", .{}) catch return buf[0..0]; │ │2349 - i += s.len; │ │2350 - } │ │2328 + i = cssColor(buf, i, "color", if (inverted) bg else fg, if (inverted) "var(--bg)" else null) orelse return buf[0..0]; │ │2329 + i = cssColor(buf, i, "background-color", if (inverted) fg else bg, if (inverted) "var(--fg)" else null) orelse return buf[0..0];│ │2330 buf[i] = '"'; │ │2352 - i += 1; │ │2353 - return buf[0..i]; │ │2331 + return buf[0 .. i + 1]; │ │2332 +} │ │2333 + │ │2334 +// append `prop:value;` at buf[i..] for the color, or for the fallback when │ │2335 +// the color is unset (nothing when both are). returns the new end, or null │ │2336 +// when it doesn't fit. │ │2337 +fn cssColor(buf: []u8, i: usize, prop: []const u8, color: ?Grid.Color, fallback: ?[]const u8) ?usize { │ │2338 + const s = if (color) |c| blk: { │ │2339 + const v = colorRgb(c); │ │2340 + break :blk std.fmt.bufPrint(buf[i..], "{s}:#{x:0>2}{x:0>2}{x:0>2};", .{ prop, v.r, v.g, v.b }) catch return null; │ │2341 + } else if (fallback) |f| │ │2342 + std.fmt.bufPrint(buf[i..], "{s}:{s};", .{ prop, f }) catch return null │ │2343 + else │ │2344 + return i; │ │2345 + return i + s.len; │ │2346 } │ │2347 │ │2348 fn appendEscapedHtml(allocator: std.mem.Allocator, out: *std.ArrayList(u8), input: []const u8) !void { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯