╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2283 return .{ 2284 .r = @intCast(@as(u16, c.r) * art_brightness / 100), 2285 .g = @intCast(@as(u16, c.g) * art_brightness / 100), 2286 .b = @intCast(@as(u16, c.b) * art_brightness / 100), 2287 }; 2288 } 2289 2290 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 2291 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 2292 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 2293 // snap such channels clear of that range so the backdrop doesn't blink or 2294 // hide text there; the ≤9/255 shift is imperceptible on terminals that 2295 // actually render truecolor. 2296 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 2297 const c = color orelse return null; 2298 const snap = struct { 2299 fn f(v: u8) u8 { 2300 return if (v >= 1 and v <= 9) 10 else v; 2301 } 2302 }.f; 2303 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2304 } 2305 2306 // composites ANSI art behind a foreground grid 2307 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 2308 art.clearGrid(); 2309 try art.build(allocator, .{ 2310 .min_size = .{ .width = null, .height = null }, 2311 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2312 }, root_focus); 2313 2314 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2315 errdefer out.deinit(); 2316 2317 if (art.getGrid()) |art_grid| { 2318 const anchor_x = switch (anchor) { 2319 .top_left => 0, 2320 .top_right => foreground.size.width -| art_grid.size.width, 2321 }; 2322 for (0..art_grid.size.height) |y| { 2323 for (0..art_grid.size.width) |x| { 2324 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2325 if (src.rune == null) continue; 2326 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2327 const dst = &out.cells.items[idx]; 2328 // composite the dimmed art behind every cell so it shows 2329 // through the whole UI: a blank cell becomes the art, while a 2330 // cell with a glyph keeps the glyph but takes the dimmed art as 2331 // its background (replacing whatever background it had, which 2332 // would otherwise obscure the art). 2333 if (cellIsBlank(dst.*)) { 2334 dst.* = src; 2335 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2336 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2337 } else { 2338 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2339 } 2340 } 2341 } 2342 } 2343 return out; 2344 } 2345 }; 2346