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