╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2590 const c = color orelse return null; 2591 const snap = struct { 2592 fn f(v: u8) u8 { 2593 return if (v >= 1 and v <= 9) 10 else v; 2594 } 2595 }.f; 2596 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2597 } 2598 2599 // composites ANSI art behind a foreground grid 2600 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, is_terminal: bool, root_focus: *Focus) !Grid { 2601 art.clearGrid(); 2602 try art.build(allocator, .{ 2603 .min_size = .{ .width = null, .height = null }, 2604 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2605 }, root_focus); 2606 2607 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2608 errdefer out.deinit(); 2609 2610 if (art.getGrid()) |art_grid| { 2611 const anchor_x = switch (anchor) { 2612 .top_left => 0, 2613 .top_right => foreground.size.width -| art_grid.size.width, 2614 }; 2615 for (0..art_grid.size.height) |y| { 2616 for (0..art_grid.size.width) |x| { 2617 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2618 if (src.rune == null) continue; 2619 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2620 const dst = &out.cells.items[idx]; 2621 // composite the dimmed art behind every cell so it shows 2622 // through the whole UI: a blank cell becomes the art, while a 2623 // cell with a glyph keeps the glyph but takes the dimmed art as 2624 // its background (replacing whatever background it had, which 2625 // would otherwise obscure the art). 2626 if (cellIsBlank(dst.*)) { 2627 dst.* = src; 2628 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2629 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2630 } else { 2631 const background_maybe = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2632 dst.style.bg = background_maybe; 2633 // change the color of text overlaying ANSI art to ensure 2634 // it is readable. don't do this in the web UI, since we 2635 // have direct control of the theme there (also, inner 2636 // scroll panes allow text to move without a re-render 2637 // by the TUI, which would break this). also don't do this 2638 // if the text is explicitly styled. 2639 if (is_terminal and dst.style.fg == null) { 2640 if (background_maybe) |background| { 2641 // use near-black and near-white, which is easier on the eyes 2642 // while retaining high contrast 2643 const luminance = (@as(u32, background.r) * 299 + 2644 @as(u32, background.g) * 587 + 2645 @as(u32, background.b) * 114) / 1000; 2646 dst.style.fg = if (luminance >= 128) 2647 .{ .r = 16, .g = 16, .b = 16 } 2648 else 2649 .{ .r = 240, .g = 240, .b = 240 }; 2650 } 2651 } 2652 } 2653 } 2654 } 2655 } 2656 return out; 2657 } 2658 }; 2659