╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2408 fn f(v: u8) u8 { 2409 return if (v >= 1 and v <= 9) 10 else v; 2410 } 2411 }.f; 2412 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2413 } 2414 2415 // composites ANSI art behind a foreground grid 2416 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 2417 art.clearGrid(); 2418 try art.build(allocator, .{ 2419 .min_size = .{ .width = null, .height = null }, 2420 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2421 }, root_focus); 2422 2423 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2424 errdefer out.deinit(); 2425 2426 if (art.getGrid()) |art_grid| { 2427 const anchor_x = switch (anchor) { 2428 .top_left => 0, 2429 .top_right => foreground.size.width -| art_grid.size.width, 2430 }; 2431 for (0..art_grid.size.height) |y| { 2432 for (0..art_grid.size.width) |x| { 2433 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2434 if (src.rune == null) continue; 2435 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2436 const dst = &out.cells.items[idx]; 2437 // composite the dimmed art behind every cell so it shows 2438 // through the whole UI: a blank cell becomes the art, while a 2439 // cell with a glyph keeps the glyph but takes the dimmed art as 2440 // its background (replacing whatever background it had, which 2441 // would otherwise obscure the art). 2442 if (cellIsBlank(dst.*)) { 2443 dst.* = src; 2444 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2445 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2446 } else { 2447 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2448 } 2449 } 2450 } 2451 } 2452 return out; 2453 } 2454 }; 2455