╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1680 }; 1681 } 1682 1683 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 1684 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 1685 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 1686 // snap such channels clear of that range so the backdrop doesn't blink or 1687 // hide text there; the ≤9/255 shift is imperceptible on terminals that 1688 // actually render truecolor. 1689 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 1690 const c = color orelse return null; 1691 const snap = struct { 1692 fn f(v: u8) u8 { 1693 return if (v >= 1 and v <= 9) 10 else v; 1694 } 1695 }.f; 1696 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 1697 } 1698 1699 // composites ANSI art behind a foreground grid 1700 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 1701 art.clearGrid(); 1702 try art.build(allocator, .{ 1703 .min_size = .{ .width = null, .height = null }, 1704 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 1705 }, root_focus); 1706 1707 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 1708 errdefer out.deinit(); 1709 1710 if (art.getGrid()) |art_grid| { 1711 const anchor_x = switch (anchor) { 1712 .top_left => 0, 1713 .top_right => foreground.size.width -| art_grid.size.width, 1714 }; 1715 for (0..art_grid.size.height) |y| { 1716 for (0..art_grid.size.width) |x| { 1717 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 1718 if (src.rune == null) continue; 1719 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 1720 const dst = &out.cells.items[idx]; 1721 // composite the dimmed art behind every cell so it shows 1722 // through the whole UI: a blank cell becomes the art, while a 1723 // cell with a glyph keeps the glyph but takes the dimmed art as 1724 // its background (replacing whatever background it had, which 1725 // would otherwise obscure the art). 1726 if (cellIsBlank(dst.*)) { 1727 dst.* = src; 1728 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 1729 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 1730 } else { 1731 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 1732 } 1733 } 1734 } 1735 } 1736 return out; 1737 } 1738 }; 1739