╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1838 // stays legible over it 1839 const art_brightness = 45; // percent 1840 1841 fn dimColor(color: ?Grid.Color) ?Grid.Color { 1842 const c = color orelse return null; 1843 return .{ 1844 .r = @intCast(@as(u16, c.r) * art_brightness / 100), 1845 .g = @intCast(@as(u16, c.g) * art_brightness / 100), 1846 .b = @intCast(@as(u16, c.b) * art_brightness / 100), 1847 }; 1848 } 1849 1850 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 1851 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 1852 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 1853 // snap such channels clear of that range so the backdrop doesn't blink or 1854 // hide text there; the ≤9/255 shift is imperceptible on terminals that 1855 // actually render truecolor. 1856 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 1857 const c = color orelse return null; 1858 const snap = struct { 1859 fn f(v: u8) u8 { 1860 return if (v >= 1 and v <= 9) 10 else v; 1861 } 1862 }.f; 1863 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 1864 } 1865 1866 // composites ANSI art behind a foreground grid 1867 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 1868 art.clearGrid(); 1869 try art.build(allocator, .{ 1870 .min_size = .{ .width = null, .height = null }, 1871 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 1872 }, root_focus); 1873 1874 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 1875 errdefer out.deinit(); 1876 1877 if (art.getGrid()) |art_grid| { 1878 const anchor_x = switch (anchor) { 1879 .top_left => 0, 1880 .top_right => foreground.size.width -| art_grid.size.width, 1881 }; 1882 for (0..art_grid.size.height) |y| { 1883 for (0..art_grid.size.width) |x| { 1884 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 1885 if (src.rune == null) continue; 1886 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 1887 const dst = &out.cells.items[idx]; 1888 // composite the dimmed art behind every cell so it shows 1889 // through the whole UI: a blank cell becomes the art, while a 1890 // cell with a glyph keeps the glyph but takes the dimmed art as 1891 // its background (replacing whatever background it had, which 1892 // would otherwise obscure the art). 1893 if (cellIsBlank(dst.*)) { 1894 dst.* = src; 1895 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 1896 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 1897 } else { 1898 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 1899 } 1900 } 1901 } 1902 } 1903 return out; 1904 } 1905 }; 1906