╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2228 // snap such channels clear of that range so the backdrop doesn't blink or 2229 // hide text there; the ≤9/255 shift is imperceptible on terminals that 2230 // actually render truecolor. 2231 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 2232 const c = color orelse return null; 2233 const snap = struct { 2234 fn f(v: u8) u8 { 2235 return if (v >= 1 and v <= 9) 10 else v; 2236 } 2237 }.f; 2238 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2239 } 2240 2241 // composites ANSI art behind a foreground grid 2242 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 2243 art.clearGrid(); 2244 try art.build(allocator, .{ 2245 .min_size = .{ .width = null, .height = null }, 2246 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2247 }, root_focus); 2248 2249 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2250 errdefer out.deinit(); 2251 2252 if (art.getGrid()) |art_grid| { 2253 const anchor_x = switch (anchor) { 2254 .top_left => 0, 2255 .top_right => foreground.size.width -| art_grid.size.width, 2256 }; 2257 for (0..art_grid.size.height) |y| { 2258 for (0..art_grid.size.width) |x| { 2259 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2260 if (src.rune == null) continue; 2261 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2262 const dst = &out.cells.items[idx]; 2263 // composite the dimmed art behind every cell so it shows 2264 // through the whole UI: a blank cell becomes the art, while a 2265 // cell with a glyph keeps the glyph but takes the dimmed art as 2266 // its background (replacing whatever background it had, which 2267 // would otherwise obscure the art). 2268 if (cellIsBlank(dst.*)) { 2269 dst.* = src; 2270 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2271 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2272 } else { 2273 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2274 } 2275 } 2276 } 2277 } 2278 return out; 2279 } 2280 }; 2281