╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1637 const rects = self.rects.items; 1638 if (index >= rects.len) return null; 1639 const cur_y = rects[index].y; 1640 if (downward) { 1641 for (rects[index + 1 ..], index + 1..) |r, i| { 1642 if (r.y > cur_y) return i; 1643 } 1644 return null; 1645 } 1646 // walk the earlier rows; the last one visited is the row above. 1647 var prev_first: ?usize = null; 1648 var i: usize = 0; 1649 while (i < rects.len and rects[i].y < cur_y) { 1650 prev_first = i; 1651 const y = rects[i].y; 1652 while (i < rects.len and rects[i].y == y) i += 1; 1653 } 1654 return prev_first; 1655 } 1656 }; 1657 1658 // an invisible widget that fills the horizontal space granted by its parent. 1659 // used inside Box(horiz) with a min_size so the box reserves space for the 1660 // children that follow, pushing them to the right. 1661 pub const Spacer = struct { 1662 focus: *Focus, 1663 grid: ?Grid, 1664 1665 pub fn init(allocator: std.mem.Allocator) !Spacer { 1666 return .{ 1667 .focus = try Focus.create(allocator, .container), 1668 .grid = null, 1669 }; 1670 } 1671 1672 pub fn deinit(self: *Spacer, allocator: std.mem.Allocator) void { 1673 self.focus.destroy(allocator); 1674 if (self.grid) |*grid| { 1675 grid.deinit(); 1676 self.grid = null; 1677 } 1678 } 1679 1680 pub fn build(self: *Spacer, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1681 _ = root_focus; 1682 self.clearGrid(); 1683 const width = constraint.max_size.width orelse return; 1684 if (width == 0) return; 1685 self.grid = try Grid.init(allocator, .{ .width = width, .height = 1 }); 1686 } 1687 1688 pub fn input(self: *Spacer, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1689 _ = self; 1690 _ = allocator; 1691 _ = key; 1692 _ = root_focus; 1693 } 1694 1695 pub fn clearGrid(self: *Spacer) void { 1696 if (self.grid) |*grid| { 1697 grid.deinit(); 1698 self.grid = null; 1699 } 1700 } 1701 1702 pub fn getGrid(self: Spacer) ?Grid { 1703 return self.grid; 1704 } 1705 1706 pub fn getFocus(self: *Spacer) *Focus { 1707 return self.focus; 1708 } 1709 }; 1710 1711 // a one-row, non-focusable status bar showing the current page's url 1712 pub const Footer = struct { 1713 focus: *Focus, 1714 grid: ?Grid, 1715 session: *Session, 1716 arena: std.heap.ArenaAllocator, 1717 1718 pub fn init(allocator: std.mem.Allocator, session: *Session) !Footer { 1719 return .{ 1720 .focus = try Focus.create(allocator, .container), 1721 .grid = null, 1722 .session = session, 1723 .arena = std.heap.ArenaAllocator.init(allocator), 1724 }; 1725 } 1726 1727 pub fn deinit(self: *Footer, allocator: std.mem.Allocator) void { 1728 self.focus.destroy(allocator); 1729 if (self.grid) |*grid| grid.deinit(); 1730 self.arena.deinit(); 1731 } 1732 1733 pub fn build(self: *Footer, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1734 _ = root_focus; 1735 self.clearGrid(); 1736 const width = constraint.max_size.width orelse return; 1737 if (width == 0) return; 1738 1739 _ = self.arena.reset(.retain_capacity); 1740 const aa = self.arena.allocator(); 1741 const path = self.session.data.current_page.urlAlloc(&self.arena) catch return; 1742 const text = if (self.session.web_port) |port| 1743 std.fmt.allocPrint(aa, "http://localhost:{d}{s}", .{ port, path }) catch return 1744 else 1745 path; 1746 1747 var grid = try Grid.init(allocator, .{ .width = width, .height = 1 }); 1748 errdefer grid.deinit(); 1749 var utf8 = (std.unicode.Utf8View.init(text) catch return).iterator(); 1750 var i: usize = 0; 1751 while (utf8.nextCodepointSlice()) |ch| { 1752 if (i == width) break; 1753 grid.cells.items[try grid.cells.at(.{ 0, i })].rune = ch; 1754 i += 1; 1755 } 1756 self.grid = grid; 1757 } 1758 1759 pub fn input(self: *Footer, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1760 _ = self; 1761 _ = allocator; 1762 _ = key; 1763 _ = root_focus; 1764 } 1765 1766 pub fn clearGrid(self: *Footer) void { 1767 if (self.grid) |*grid| { 1768 grid.deinit(); 1769 self.grid = null; 1770 } 1771 } 1772 1773 pub fn getGrid(self: Footer) ?Grid { 1774 return self.grid; 1775 } 1776 1777 pub fn getFocus(self: *Footer) *Focus { 1778 return self.focus; 1779 } 1780 }; 1781 1782 // a single-child wrapper that builds the child at its natural size and 1783 // positions its grid in the middle of the area granted by the parent 1784 pub const Center = struct { 1785 focus: *Focus, 1786 grid: ?Grid, 1787 child: *Widget, 1788 1789 pub fn init(allocator: std.mem.Allocator, child_widget: Widget) !Center { 1790 const child = try allocator.create(Widget); 1791 errdefer allocator.destroy(child); 1792 child.* = child_widget; 1793 return .{ 1794 .focus = try Focus.create(allocator, .container), 1795 .grid = null, 1796 .child = child, 1797 }; 1798 } 1799 1800 pub fn deinit(self: *Center, allocator: std.mem.Allocator) void { 1801 self.focus.destroy(allocator); 1802 if (self.grid) |*grid| { 1803 grid.deinit(); 1804 self.grid = null; 1805 } 1806 self.child.deinit(allocator); 1807 allocator.destroy(self.child); 1808 } 1809 1810 pub fn build(self: *Center, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1811 self.clearGrid(); 1812 self.getFocus().clear(); 1813 1814 // build the child without forcing it to fill min_size; it sizes 1815 // itself to its content within the available max. 1816 try self.child.build(allocator, .{ 1817 .min_size = .{ .width = null, .height = null }, 1818 .max_size = constraint.max_size, 1819 }, root_focus); 1820 1821 const child_grid = self.child.getGrid() orelse return; 1822 1823 // prefer max when given; otherwise grow to max(min, child) so that 1824 // when only a min is set (e.g. the wasm path passes viewport rows 1825 // as min_height with no max), we can still vertically center while 1826 // letting taller content extend past the min. 1827 const width = if (constraint.max_size.width) |w| w else if (constraint.min_size.width) |min_w| @max(min_w, child_grid.size.width) else child_grid.size.width; 1828 const height = if (constraint.max_size.height) |h| h else if (constraint.min_size.height) |min_h| @max(min_h, child_grid.size.height) else child_grid.size.height; 1829 if (width == 0 or height == 0) return; 1830 1831 const offset_x: usize = (width -| child_grid.size.width) / 2; 1832 const offset_y: usize = (height -| child_grid.size.height) / 2; 1833 1834 var grid = try Grid.init(allocator, .{ .width = width, .height = height }); 1835 errdefer grid.deinit(); 1836 try grid.drawGrid(child_grid, offset_x, offset_y); 1837 try self.getFocus().addChild(allocator, self.child.getFocus(), child_grid.size, offset_x, offset_y); 1838 self.getFocus().child_id = self.child.getFocus().id; 1839 1840 self.grid = grid; 1841 } 1842 1843 pub fn input(self: *Center, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1844 try self.child.input(allocator, key, root_focus); 1845 } 1846 1847 pub fn clearGrid(self: *Center) void { 1848 if (self.grid) |*grid| { 1849 grid.deinit(); 1850 self.grid = null; 1851 } 1852 self.child.clearGrid(); 1853 } 1854 1855 pub fn getGrid(self: Center) ?Grid { 1856 return self.grid; 1857 } 1858 1859 pub fn getFocus(self: *Center) *Focus { 1860 return self.focus; 1861 } 1862 }; 1863 1864 // renders truecolor ANSI art 1865 pub const AnsiArt = struct { 1866 focus: *Focus, 1867 grid: ?Grid, 1868 content: []const u8, 1869 1870 pub fn init(allocator: std.mem.Allocator, content: []const u8) !AnsiArt { 1871 return .{ 1872 .focus = try Focus.create(allocator, .container), 1873 .grid = null, 1874 .content = content, 1875 }; 1876 } 1877 1878 pub fn deinit(self: *AnsiArt, allocator: std.mem.Allocator) void { 1879 self.focus.destroy(allocator); 1880 if (self.grid) |*grid| { 1881 grid.deinit(); 1882 self.grid = null; 1883 } 1884 } 1885 1886 pub fn build(self: *AnsiArt, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1887 _ = root_focus; 1888 self.clearGrid(); 1889 1890 // parse into rows of cells, then copy into a rectangular grid 1891 var rows: std.ArrayList(std.ArrayList(Grid.Cell)) = .empty; 1892 defer { 1893 for (rows.items) |*row| row.deinit(allocator); 1894 rows.deinit(allocator); 1895 } 1896 var row: std.ArrayList(Grid.Cell) = .empty; 1897 errdefer row.deinit(allocator); 1898 1899 var style: Grid.Style = .{}; 1900 var width: usize = 0; 1901 const content = self.content; 1902 var i: usize = 0; 1903 while (i < content.len) { 1904 const byte = content[i]; 1905 if (byte == '\n') { 1906 width = @max(width, row.items.len); 1907 try rows.append(allocator, row); 1908 row = .empty; 1909 i += 1; 1910 } else if (byte == 0x1B and i + 1 < content.len and content[i + 1] == '[') { 1911 // CSI: scan to the final byte (0x40..0x7E); apply it if it's 'm' 1912 var j = i + 2; 1913 while (j < content.len and !(content[j] >= 0x40 and content[j] <= 0x7E)) j += 1; 1914 if (j >= content.len) { 1915 i = content.len; // malformed trailing escape; stop 1916 } else { 1917 if (content[j] == 'm') applySgr(&style, content[i + 2 .. j]); 1918 i = j + 1; 1919 } 1920 } else { 1921 const len = std.unicode.utf8ByteSequenceLength(byte) catch 1; 1922 const end = @min(content.len, i + len); 1923 const rune = content[i..end]; 1924 const transparent = end - i == 1 and rune[0] == ' ' and 1925 style.fg == null and style.bg == null and !style.inverted; 1926 try row.append(allocator, .{ 1927 .rune = if (transparent) null else rune, 1928 .style = style, 1929 }); 1930 i = end; 1931 } 1932 } 1933 // a trailing row with content but no closing newline 1934 if (row.items.len > 0) { 1935 width = @max(width, row.items.len); 1936 try rows.append(allocator, row); 1937 } else { 1938 row.deinit(allocator); 1939 } 1940 row = .empty; // ownership moved into rows (or freed); keep errdefer safe 1941 1942 const height = rows.items.len; 1943 if (width == 0 or height == 0) return; 1944 1945 const clamped_w = @min(width, constraint.max_size.width orelse width); 1946 const clamped_h = @min(height, constraint.max_size.height orelse height); 1947 1948 var grid = try Grid.init(allocator, .{ .width = clamped_w, .height = clamped_h }); 1949 errdefer grid.deinit(); 1950 for (rows.items[0..clamped_h], 0..) |r, y| { 1951 const n = @min(r.items.len, clamped_w); 1952 for (r.items[0..n], 0..) |cell, x| { 1953 grid.cells.items[try grid.cells.at(.{ y, x })] = cell; 1954 } 1955 } 1956 self.grid = grid; 1957 } 1958 1959 pub fn clearGrid(self: *AnsiArt) void { 1960 if (self.grid) |*grid| { 1961 grid.deinit(); 1962 self.grid = null; 1963 } 1964 } 1965 1966 pub fn getGrid(self: AnsiArt) ?Grid { 1967 return self.grid; 1968 } 1969 1970 pub fn getFocus(self: *AnsiArt) *Focus { 1971 return self.focus; 1972 } 1973 1974 fn applySgr(style: *Grid.Style, params: []const u8) void { 1975 var nums: [16]u32 = undefined; 1976 var n: usize = 0; 1977 var it = std.mem.splitScalar(u8, params, ';'); 1978 while (it.next()) |tok| { 1979 if (n >= nums.len) break; 1980 // an empty parameter (e.g. bare "\x1b[m") means 0 1981 nums[n] = std.fmt.parseInt(u32, tok, 10) catch 0; 1982 n += 1; 1983 } 1984 if (n == 0) { 1985 style.* = .{}; 1986 return; 1987 } 1988 var i: usize = 0; 1989 while (i < n) : (i += 1) { 1990 switch (nums[i]) { 1991 0 => style.* = .{}, 1992 7 => style.inverted = true, 1993 27 => style.inverted = false, 1994 39 => style.fg = null, 1995 49 => style.bg = null, 1996 38, 48 => { 1997 // truecolor form: 38;2;r;g;b — anything else is ignored 1998 if (i + 4 < n and nums[i + 1] == 2) { 1999 const c = Grid.Color{ 2000 .r = @truncate(nums[i + 2]), 2001 .g = @truncate(nums[i + 3]), 2002 .b = @truncate(nums[i + 4]), 2003 }; 2004 if (nums[i] == 38) style.fg = c else style.bg = c; 2005 i += 4; 2006 } 2007 }, 2008 else => {}, 2009 } 2010 } 2011 } 2012 }; 2013 2014 // a full-screen wrapper that renders ANSI art behind whatever page it wraps 2015 pub const AnsiBackground = struct { 2016 grid: ?Grid, 2017 child: *Widget, 2018 art: AnsiArt, 2019 session: *Session, 2020 2021 pub fn init(allocator: std.mem.Allocator, child_widget: Widget, art_content: []const u8, session: *Session) !AnsiBackground { 2022 var cw = child_widget; 2023 const child = allocator.create(Widget) catch |e| { 2024 cw.deinit(allocator); 2025 return e; 2026 }; 2027 child.* = cw; 2028 errdefer { 2029 child.deinit(allocator); 2030 allocator.destroy(child); 2031 } 2032 return .{ .grid = null, .child = child, .art = try AnsiArt.init(allocator, art_content), .session = session }; 2033 } 2034 2035 pub fn deinit(self: *AnsiBackground, allocator: std.mem.Allocator) void { 2036 if (self.grid) |*grid| grid.deinit(); 2037 self.art.deinit(allocator); 2038 self.child.deinit(allocator); 2039 allocator.destroy(self.child); 2040 } 2041 2042 pub fn build(self: *AnsiBackground, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2043 self.clearGrid(); 2044 2045 // make the wrapped page fill the whole available area 2046 try self.child.build(allocator, .{ 2047 .min_size = .{ 2048 .width = constraint.max_size.width orelse constraint.min_size.width, 2049 .height = constraint.max_size.height orelse constraint.min_size.height, 2050 }, 2051 .max_size = constraint.max_size, 2052 }, root_focus); 2053 2054 if (self.session.data.enable_ansi) { 2055 if (self.child.getGrid()) |fg| { 2056 self.grid = try artBehind(allocator, fg, &self.art, .top_right, root_focus); 2057 } 2058 } 2059 } 2060 2061 pub fn input(self: *AnsiBackground, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2062 try self.child.input(allocator, key, root_focus); 2063 } 2064 2065 pub fn clearGrid(self: *AnsiBackground) void { 2066 if (self.grid) |*grid| { 2067 grid.deinit(); 2068 self.grid = null; 2069 } 2070 self.child.clearGrid(); 2071 self.art.clearGrid(); 2072 } 2073 2074 pub fn getGrid(self: AnsiBackground) ?Grid { 2075 return self.grid orelse self.child.getGrid(); 2076 } 2077 2078 pub fn getFocus(self: *AnsiBackground) *Focus { 2079 return self.child.getFocus(); 2080 } 2081 2082 // which top corner the art hugs. 2083 const ArtAnchor = enum { top_left, top_right }; 2084 2085 // a foreground cell counts as blank if it's empty or a bare space without styling 2086 fn cellIsBlank(cell: Grid.Cell) bool { 2087 if (cell.rune) |rune| { 2088 return std.mem.eql(u8, rune, " ") and 2089 cell.style.fg == null and cell.style.bg == null and !cell.style.inverted; 2090 } 2091 return true; 2092 } 2093 2094 // the art is dimmed to this fraction of its brightness so foreground text 2095 // stays legible over it 2096 const art_brightness = 45; // percent 2097 2098 fn dimColor(color: ?Grid.Color) ?Grid.Color { 2099 const c = color orelse return null; 2100 return .{ 2101 .r = @intCast(@as(u16, c.r) * art_brightness / 100), 2102 .g = @intCast(@as(u16, c.g) * art_brightness / 100), 2103 .b = @intCast(@as(u16, c.b) * art_brightness / 100), 2104 }; 2105 } 2106 2107 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 2108 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 2109 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 2110 // snap such channels clear of that range so the backdrop doesn't blink or 2111 // hide text there; the ≤9/255 shift is imperceptible on terminals that 2112 // actually render truecolor. 2113 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 2114 const c = color orelse return null; 2115 const snap = struct { 2116 fn f(v: u8) u8 { 2117 return if (v >= 1 and v <= 9) 10 else v; 2118 } 2119 }.f; 2120 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 2121 } 2122 2123 // composites ANSI art behind a foreground grid 2124 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 2125 art.clearGrid(); 2126 try art.build(allocator, .{ 2127 .min_size = .{ .width = null, .height = null }, 2128 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 2129 }, root_focus); 2130 2131 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 2132 errdefer out.deinit(); 2133 2134 if (art.getGrid()) |art_grid| { 2135 const anchor_x = switch (anchor) { 2136 .top_left => 0, 2137 .top_right => foreground.size.width -| art_grid.size.width, 2138 }; 2139 for (0..art_grid.size.height) |y| { 2140 for (0..art_grid.size.width) |x| { 2141 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 2142 if (src.rune == null) continue; 2143 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 2144 const dst = &out.cells.items[idx]; 2145 // composite the dimmed art behind every cell so it shows 2146 // through the whole UI: a blank cell becomes the art, while a 2147 // cell with a glyph keeps the glyph but takes the dimmed art as 2148 // its background (replacing whatever background it had, which 2149 // would otherwise obscure the art). 2150 if (cellIsBlank(dst.*)) { 2151 dst.* = src; 2152 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 2153 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 2154 } else { 2155 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 2156 } 2157 } 2158 } 2159 } 2160 return out; 2161 } 2162 }; 2163