╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
946 const glyph_bg_brightness = 45; // percent 947 948 // a glyph sitting over the art also gets its foreground pinned to this color 949 // (unless it set its own), so the text stays legible 950 const glyph_fg_over_art = Grid.Color{ .r = 235, .g = 235, .b = 235 }; 951 952 fn dimColor(color: ?Grid.Color) ?Grid.Color { 953 const c = color orelse return null; 954 return .{ 955 .r = @intCast(@as(u16, c.r) * glyph_bg_brightness / 100), 956 .g = @intCast(@as(u16, c.g) * glyph_bg_brightness / 100), 957 .b = @intCast(@as(u16, c.b) * glyph_bg_brightness / 100), 958 }; 959 } 960 961 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 962 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 963 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 964 // snap such channels clear of that range so the backdrop doesn't blink or 965 // hide text there; the ≤9/255 shift is imperceptible on terminals that 966 // actually render truecolor. 967 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 968 const c = color orelse return null; 969 const snap = struct { 970 fn f(v: u8) u8 { 971 return if (v >= 1 and v <= 9) 10 else v; 972 } 973 }.f; 974 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 975 } 976 977 // composites ANSI art behind a foreground grid 978 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 979 art.clearGrid(); 980 try art.build(allocator, .{ 981 .min_size = .{ .width = null, .height = null }, 982 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 983 }, root_focus); 984 985 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 986 errdefer out.deinit(); 987 988 if (art.getGrid()) |art_grid| { 989 const anchor_x = switch (anchor) { 990 .top_left => 0, 991 .top_right => foreground.size.width -| art_grid.size.width, 992 }; 993 for (0..art_grid.size.height) |y| { 994 for (0..art_grid.size.width) |x| { 995 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 996 if (src.rune == null) continue; 997 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 998 const dst = &out.cells.items[idx]; 999 if (cellIsBlank(dst.*)) { 1000 dst.* = src; 1001 dst.style.fg = sgrSafe(dst.style.fg); 1002 dst.style.bg = sgrSafe(dst.style.bg); 1003 } else if (dst.style.bg == null) { 1004 dst.style.bg = sgrSafe(dimColor(artCellColor(src.style))); 1005 if (dst.style.fg == null) dst.style.fg = glyph_fg_over_art; 1006 } 1007 } 1008 } 1009 } 1010 return out; 1011 } 1012 }; 1013