╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2174 fn f(v: u8) u8 { 2175 return if (v >= 1 and v <= 9) 10 else v; 2176 } 2177 }.f; 2178 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2179 } 2180 2181 // composites ANSI art behind a foreground grid 2182 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 2183 art.clearGrid(); 2184 try art.build(allocator, .{ 2185 .min_size = .{ .width = null, .height = null }, 2186 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2187 }, root_focus); 2188 2189 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2190 errdefer out.deinit(); 2191 2192 if (art.getGrid()) |art_grid| { 2193 const anchor_x = switch (anchor) { 2194 .top_left => 0, 2195 .top_right => foreground.size.width -| art_grid.size.width, 2196 }; 2197 for (0..art_grid.size.height) |y| { 2198 for (0..art_grid.size.width) |x| { 2199 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2200 if (src.rune == null) continue; 2201 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2202 const dst = &out.cells.items[idx]; 2203 // composite the dimmed art behind every cell so it shows 2204 // through the whole UI: a blank cell becomes the art, while a 2205 // cell with a glyph keeps the glyph but takes the dimmed art as 2206 // its background (replacing whatever background it had, which 2207 // would otherwise obscure the art). 2208 if (cellIsBlank(dst.*)) { 2209 dst.* = src; 2210 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2211 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2212 } else { 2213 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2214 } 2215 } 2216 } 2217 } 2218 return out; 2219 } 2220 }; 2221