╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1432 .r = @intCast((@as(u16, f.r) + b.r) / 2), 1433 .g = @intCast((@as(u16, f.g) + b.g) / 2), 1434 .b = @intCast((@as(u16, f.b) + b.b) / 2), 1435 }; 1436 } 1437 1438 // behind a visible glyph the art color is dimmed to this fraction of its 1439 // brightness so light terminal text stays legible on top of it 1440 const glyph_bg_brightness = 45; // percent 1441 1442 // a glyph sitting over the art also gets its foreground pinned to this color 1443 // (unless it set its own), so the text stays legible 1444 const glyph_fg_over_art = Grid.Color{ .r = 235, .g = 235, .b = 235 }; 1445 1446 fn dimColor(color: ?Grid.Color) ?Grid.Color { 1447 const c = color orelse return null; 1448 return .{ 1449 .r = @intCast(@as(u16, c.r) * glyph_bg_brightness / 100), 1450 .g = @intCast(@as(u16, c.g) * glyph_bg_brightness / 100), 1451 .b = @intCast(@as(u16, c.b) * glyph_bg_brightness / 100), 1452 }; 1453 } 1454 1455 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 1456 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 1457 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 1458 // snap such channels clear of that range so the backdrop doesn't blink or 1459 // hide text there; the ≤9/255 shift is imperceptible on terminals that 1460 // actually render truecolor. 1461 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 1462 const c = color orelse return null; 1463 const snap = struct { 1464 fn f(v: u8) u8 { 1465 return if (v >= 1 and v <= 9) 10 else v; 1466 } 1467 }.f; 1468 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 1469 } 1470 1471 // composites ANSI art behind a foreground grid 1472 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 1473 art.clearGrid(); 1474 try art.build(allocator, .{ 1475 .min_size = .{ .width = null, .height = null }, 1476 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 1477 }, root_focus); 1478 1479 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 1480 errdefer out.deinit(); 1481 1482 if (art.getGrid()) |art_grid| { 1483 const anchor_x = switch (anchor) { 1484 .top_left => 0, 1485 .top_right => foreground.size.width -| art_grid.size.width, 1486 }; 1487 for (0..art_grid.size.height) |y| { 1488 for (0..art_grid.size.width) |x| { 1489 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 1490 if (src.rune == null) continue; 1491 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 1492 const dst = &out.cells.items[idx]; 1493 if (cellIsBlank(dst.*)) { 1494 dst.* = src; 1495 dst.style.fg = sgrSafe(dst.style.fg); 1496 dst.style.bg = sgrSafe(dst.style.bg); 1497 } else if (dst.style.bg == null) { 1498 dst.style.bg = sgrSafe(dimColor(artCellColor(src.style))); 1499 if (dst.style.fg == null) dst.style.fg = glyph_fg_over_art; 1500 } 1501 } 1502 } 1503 } 1504 return out; 1505 } 1506 }; 1507