╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1383 } 1384 1385 pub fn getFocus(self: *Scroll) *Focus { 1386 return self.scroll.getFocus(); 1387 } 1388 1389 pub fn getSelectedIndex(self: Scroll) ?usize { 1390 const in = self.scroll.child.flow_box; 1391 const child_id = in.focus.child_id orelse return null; 1392 return in.indexOfFocusId(child_id); 1393 } 1394 1395 fn inner(self: *Scroll) *FlowBox { 1396 return &self.scroll.child.flow_box; 1397 } 1398 }; 1399 }; 1400 1401 // an invisible widget that fills the horizontal space granted by its parent. 1402 // used inside Box(horiz) with a min_size so the box reserves space for the 1403 // children that follow, pushing them to the right. 1404 pub const Spacer = struct { 1405 focus: *Focus, 1406 grid: ?Grid, 1407 1408 pub fn init(allocator: std.mem.Allocator) !Spacer { 1409 return .{ 1410 .focus = try Focus.create(allocator, .container), 1411 .grid = null, 1412 }; 1413 } 1414 1415 pub fn deinit(self: *Spacer, allocator: std.mem.Allocator) void { 1416 self.focus.destroy(allocator); 1417 if (self.grid) |*grid| { 1418 grid.deinit(); 1419 self.grid = null; 1420 } 1421 } 1422 1423 pub fn build(self: *Spacer, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1424 _ = root_focus; 1425 self.clearGrid(); 1426 const width = constraint.max_size.width orelse return; 1427 if (width == 0) return; 1428 self.grid = try Grid.init(allocator, .{ .width = width, .height = 1 }); 1429 } 1430 1431 pub fn input(self: *Spacer, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1432 _ = self; 1433 _ = allocator; 1434 _ = key; 1435 _ = root_focus; 1436 } 1437 1438 pub fn clearGrid(self: *Spacer) void { 1439 if (self.grid) |*grid| { 1440 grid.deinit(); 1441 self.grid = null; 1442 } 1443 } 1444 1445 pub fn getGrid(self: Spacer) ?Grid { 1446 return self.grid; 1447 } 1448 1449 pub fn getFocus(self: *Spacer) *Focus { 1450 return self.focus; 1451 } 1452 }; 1453 1454 // a one-row, non-focusable status bar showing the current page's url 1455 pub const Footer = struct { 1456 focus: *Focus, 1457 grid: ?Grid, 1458 session: *Session, 1459 arena: std.heap.ArenaAllocator, 1460 1461 pub fn init(allocator: std.mem.Allocator, session: *Session) !Footer { 1462 return .{ 1463 .focus = try Focus.create(allocator, .container), 1464 .grid = null, 1465 .session = session, 1466 .arena = std.heap.ArenaAllocator.init(allocator), 1467 }; 1468 } 1469 1470 pub fn deinit(self: *Footer, allocator: std.mem.Allocator) void { 1471 self.focus.destroy(allocator); 1472 if (self.grid) |*grid| grid.deinit(); 1473 self.arena.deinit(); 1474 } 1475 1476 pub fn build(self: *Footer, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1477 _ = root_focus; 1478 self.clearGrid(); 1479 const width = constraint.max_size.width orelse return; 1480 if (width == 0) return; 1481 1482 _ = self.arena.reset(.retain_capacity); 1483 const aa = self.arena.allocator(); 1484 const path = self.session.data.current_page.urlAlloc(&self.arena) catch return; 1485 const text = if (self.session.web_port) |port| 1486 std.fmt.allocPrint(aa, "http://localhost:{d}{s}", .{ port, path }) catch return 1487 else 1488 path; 1489 1490 var grid = try Grid.init(allocator, .{ .width = width, .height = 1 }); 1491 errdefer grid.deinit(); 1492 var utf8 = (std.unicode.Utf8View.init(text) catch return).iterator(); 1493 var i: usize = 0; 1494 while (utf8.nextCodepointSlice()) |ch| { 1495 if (i == width) break; 1496 grid.cells.items[try grid.cells.at(.{ 0, i })].rune = ch; 1497 i += 1; 1498 } 1499 self.grid = grid; 1500 } 1501 1502 pub fn input(self: *Footer, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1503 _ = self; 1504 _ = allocator; 1505 _ = key; 1506 _ = root_focus; 1507 } 1508 1509 pub fn clearGrid(self: *Footer) void { 1510 if (self.grid) |*grid| { 1511 grid.deinit(); 1512 self.grid = null; 1513 } 1514 } 1515 1516 pub fn getGrid(self: Footer) ?Grid { 1517 return self.grid; 1518 } 1519 1520 pub fn getFocus(self: *Footer) *Focus { 1521 return self.focus; 1522 } 1523 }; 1524 1525 // a single-child wrapper that builds the child at its natural size and 1526 // positions its grid in the middle of the area granted by the parent 1527 pub const Center = struct { 1528 focus: *Focus, 1529 grid: ?Grid, 1530 child: *Widget, 1531 1532 pub fn init(allocator: std.mem.Allocator, child_widget: Widget) !Center { 1533 const child = try allocator.create(Widget); 1534 errdefer allocator.destroy(child); 1535 child.* = child_widget; 1536 return .{ 1537 .focus = try Focus.create(allocator, .container), 1538 .grid = null, 1539 .child = child, 1540 }; 1541 } 1542 1543 pub fn deinit(self: *Center, allocator: std.mem.Allocator) void { 1544 self.focus.destroy(allocator); 1545 if (self.grid) |*grid| { 1546 grid.deinit(); 1547 self.grid = null; 1548 } 1549 self.child.deinit(allocator); 1550 allocator.destroy(self.child); 1551 } 1552 1553 pub fn build(self: *Center, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1554 self.clearGrid(); 1555 self.getFocus().clear(); 1556 1557 // build the child without forcing it to fill min_size; it sizes 1558 // itself to its content within the available max. 1559 try self.child.build(allocator, .{ 1560 .min_size = .{ .width = null, .height = null }, 1561 .max_size = constraint.max_size, 1562 }, root_focus); 1563 1564 const child_grid = self.child.getGrid() orelse return; 1565 1566 // prefer max when given; otherwise grow to max(min, child) so that 1567 // when only a min is set (e.g. the wasm path passes viewport rows 1568 // as min_height with no max), we can still vertically center while 1569 // letting taller content extend past the min. 1570 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; 1571 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; 1572 if (width == 0 or height == 0) return; 1573 1574 const offset_x: usize = (width -| child_grid.size.width) / 2; 1575 const offset_y: usize = (height -| child_grid.size.height) / 2; 1576 1577 var grid = try Grid.init(allocator, .{ .width = width, .height = height }); 1578 errdefer grid.deinit(); 1579 try grid.drawGrid(child_grid, offset_x, offset_y); 1580 try self.getFocus().addChild(allocator, self.child.getFocus(), child_grid.size, offset_x, offset_y); 1581 self.getFocus().child_id = self.child.getFocus().id; 1582 1583 self.grid = grid; 1584 } 1585 1586 pub fn input(self: *Center, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1587 try self.child.input(allocator, key, root_focus); 1588 } 1589 1590 pub fn clearGrid(self: *Center) void { 1591 if (self.grid) |*grid| { 1592 grid.deinit(); 1593 self.grid = null; 1594 } 1595 self.child.clearGrid(); 1596 } 1597 1598 pub fn getGrid(self: Center) ?Grid { 1599 return self.grid; 1600 } 1601 1602 pub fn getFocus(self: *Center) *Focus { 1603 return self.focus; 1604 } 1605 }; 1606 1607 // renders truecolor ANSI art 1608 pub const AnsiArt = struct { 1609 focus: *Focus, 1610 grid: ?Grid, 1611 content: []const u8, 1612 1613 pub fn init(allocator: std.mem.Allocator, content: []const u8) !AnsiArt { 1614 return .{ 1615 .focus = try Focus.create(allocator, .container), 1616 .grid = null, 1617 .content = content, 1618 }; 1619 } 1620 1621 pub fn deinit(self: *AnsiArt, allocator: std.mem.Allocator) void { 1622 self.focus.destroy(allocator); 1623 if (self.grid) |*grid| { 1624 grid.deinit(); 1625 self.grid = null; 1626 } 1627 } 1628 1629 pub fn build(self: *AnsiArt, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1630 _ = root_focus; 1631 self.clearGrid(); 1632 1633 // parse into rows of cells, then copy into a rectangular grid 1634 var rows: std.ArrayList(std.ArrayList(Grid.Cell)) = .empty; 1635 defer { 1636 for (rows.items) |*row| row.deinit(allocator); 1637 rows.deinit(allocator); 1638 } 1639 var row: std.ArrayList(Grid.Cell) = .empty; 1640 errdefer row.deinit(allocator); 1641 1642 var style: Grid.Style = .{}; 1643 var width: usize = 0; 1644 const content = self.content; 1645 var i: usize = 0; 1646 while (i < content.len) { 1647 const byte = content[i]; 1648 if (byte == '\n') { 1649 width = @max(width, row.items.len); 1650 try rows.append(allocator, row); 1651 row = .empty; 1652 i += 1; 1653 } else if (byte == 0x1B and i + 1 < content.len and content[i + 1] == '[') { 1654 // CSI: scan to the final byte (0x40..0x7E); apply it if it's 'm' 1655 var j = i + 2; 1656 while (j < content.len and !(content[j] >= 0x40 and content[j] <= 0x7E)) j += 1; 1657 if (j >= content.len) { 1658 i = content.len; // malformed trailing escape; stop 1659 } else { 1660 if (content[j] == 'm') applySgr(&style, content[i + 2 .. j]); 1661 i = j + 1; 1662 } 1663 } else { 1664 const len = std.unicode.utf8ByteSequenceLength(byte) catch 1; 1665 const end = @min(content.len, i + len); 1666 const rune = content[i..end]; 1667 const transparent = end - i == 1 and rune[0] == ' ' and 1668 style.fg == null and style.bg == null and !style.inverted; 1669 try row.append(allocator, .{ 1670 .rune = if (transparent) null else rune, 1671 .style = style, 1672 }); 1673 i = end; 1674 } 1675 } 1676 // a trailing row with content but no closing newline 1677 if (row.items.len > 0) { 1678 width = @max(width, row.items.len); 1679 try rows.append(allocator, row); 1680 } else { 1681 row.deinit(allocator); 1682 } 1683 row = .empty; // ownership moved into rows (or freed); keep errdefer safe 1684 1685 const height = rows.items.len; 1686 if (width == 0 or height == 0) return; 1687 1688 const clamped_w = @min(width, constraint.max_size.width orelse width); 1689 const clamped_h = @min(height, constraint.max_size.height orelse height); 1690 1691 var grid = try Grid.init(allocator, .{ .width = clamped_w, .height = clamped_h }); 1692 errdefer grid.deinit(); 1693 for (rows.items[0..clamped_h], 0..) |r, y| { 1694 const n = @min(r.items.len, clamped_w); 1695 for (r.items[0..n], 0..) |cell, x| { 1696 grid.cells.items[try grid.cells.at(.{ y, x })] = cell; 1697 } 1698 } 1699 self.grid = grid; 1700 } 1701 1702 pub fn clearGrid(self: *AnsiArt) void { 1703 if (self.grid) |*grid| { 1704 grid.deinit(); 1705 self.grid = null; 1706 } 1707 } 1708 1709 pub fn getGrid(self: AnsiArt) ?Grid { 1710 return self.grid; 1711 } 1712 1713 pub fn getFocus(self: *AnsiArt) *Focus { 1714 return self.focus; 1715 } 1716 1717 fn applySgr(style: *Grid.Style, params: []const u8) void { 1718 var nums: [16]u32 = undefined; 1719 var n: usize = 0; 1720 var it = std.mem.splitScalar(u8, params, ';'); 1721 while (it.next()) |tok| { 1722 if (n >= nums.len) break; 1723 // an empty parameter (e.g. bare "\x1b[m") means 0 1724 nums[n] = std.fmt.parseInt(u32, tok, 10) catch 0; 1725 n += 1; 1726 } 1727 if (n == 0) { 1728 style.* = .{}; 1729 return; 1730 } 1731 var i: usize = 0; 1732 while (i < n) : (i += 1) { 1733 switch (nums[i]) { 1734 0 => style.* = .{}, 1735 7 => style.inverted = true, 1736 27 => style.inverted = false, 1737 39 => style.fg = null, 1738 49 => style.bg = null, 1739 38, 48 => { 1740 // truecolor form: 38;2;r;g;b — anything else is ignored 1741 if (i + 4 < n and nums[i + 1] == 2) { 1742 const c = Grid.Color{ 1743 .r = @truncate(nums[i + 2]), 1744 .g = @truncate(nums[i + 3]), 1745 .b = @truncate(nums[i + 4]), 1746 }; 1747 if (nums[i] == 38) style.fg = c else style.bg = c; 1748 i += 4; 1749 } 1750 }, 1751 else => {}, 1752 } 1753 } 1754 } 1755 }; 1756 1757 // a full-screen wrapper that renders ANSI art behind whatever page it wraps 1758 pub const AnsiBackground = struct { 1759 grid: ?Grid, 1760 child: *Widget, 1761 art: AnsiArt, 1762 session: *Session, 1763 1764 pub fn init(allocator: std.mem.Allocator, child_widget: Widget, art_content: []const u8, session: *Session) !AnsiBackground { 1765 var cw = child_widget; 1766 const child = allocator.create(Widget) catch |e| { 1767 cw.deinit(allocator); 1768 return e; 1769 }; 1770 child.* = cw; 1771 errdefer { 1772 child.deinit(allocator); 1773 allocator.destroy(child); 1774 } 1775 return .{ .grid = null, .child = child, .art = try AnsiArt.init(allocator, art_content), .session = session }; 1776 } 1777 1778 pub fn deinit(self: *AnsiBackground, allocator: std.mem.Allocator) void { 1779 if (self.grid) |*grid| grid.deinit(); 1780 self.art.deinit(allocator); 1781 self.child.deinit(allocator); 1782 allocator.destroy(self.child); 1783 } 1784 1785 pub fn build(self: *AnsiBackground, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1786 self.clearGrid(); 1787 1788 // make the wrapped page fill the whole available area 1789 try self.child.build(allocator, .{ 1790 .min_size = .{ 1791 .width = constraint.max_size.width orelse constraint.min_size.width, 1792 .height = constraint.max_size.height orelse constraint.min_size.height, 1793 }, 1794 .max_size = constraint.max_size, 1795 }, root_focus); 1796 1797 if (self.session.data.enable_ansi) { 1798 if (self.child.getGrid()) |fg| { 1799 self.grid = try artBehind(allocator, fg, &self.art, .top_right, root_focus); 1800 } 1801 } 1802 } 1803 1804 pub fn input(self: *AnsiBackground, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1805 try self.child.input(allocator, key, root_focus); 1806 } 1807 1808 pub fn clearGrid(self: *AnsiBackground) void { 1809 if (self.grid) |*grid| { 1810 grid.deinit(); 1811 self.grid = null; 1812 } 1813 self.child.clearGrid(); 1814 self.art.clearGrid(); 1815 } 1816 1817 pub fn getGrid(self: AnsiBackground) ?Grid { 1818 return self.grid orelse self.child.getGrid(); 1819 } 1820 1821 pub fn getFocus(self: *AnsiBackground) *Focus { 1822 return self.child.getFocus(); 1823 } 1824 1825 // which top corner the art hugs. 1826 const ArtAnchor = enum { top_left, top_right }; 1827 1828 // a foreground cell counts as blank if it's empty or a bare space without styling 1829 fn cellIsBlank(cell: Grid.Cell) bool { 1830 if (cell.rune) |rune| { 1831 return std.mem.eql(u8, rune, " ") and 1832 cell.style.fg == null and cell.style.bg == null and !cell.style.inverted; 1833 } 1834 return true; 1835 } 1836 1837 // the art is dimmed to this fraction of its brightness so foreground text 1838 // stays legible over it 1839 const art_brightness = 45; // percent 1840 1841 fn dimColor(color: ?Grid.Color) ?Grid.Color { 1842 const c = color orelse return null; 1843 return .{ 1844 .r = @intCast(@as(u16, c.r) * art_brightness / 100), 1845 .g = @intCast(@as(u16, c.g) * art_brightness / 100), 1846 .b = @intCast(@as(u16, c.b) * art_brightness / 100), 1847 }; 1848 } 1849 1850 // terminals that don't support truecolor misparse a "38;2;r;g;b"/"48;2;…" 1851 // SGR as a list of plain SGR codes, so any channel value in 1..9 turns on 1852 // a text attribute (5/6 = blink, 7 = inverse, 8 = conceal, …). 1853 // snap such channels clear of that range so the backdrop doesn't blink or 1854 // hide text there; the ≤9/255 shift is imperceptible on terminals that 1855 // actually render truecolor. 1856 fn sgrSafe(color: ?Grid.Color) ?Grid.Color { 1857 const c = color orelse return null; 1858 const snap = struct { 1859 fn f(v: u8) u8 { 1860 return if (v >= 1 and v <= 9) 10 else v; 1861 } 1862 }.f; 1863 return .{ .r = snap(c.r), .g = snap(c.g), .b = snap(c.b) }; 1864 } 1865 1866 // composites ANSI art behind a foreground grid 1867 fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { 1868 art.clearGrid(); 1869 try art.build(allocator, .{ 1870 .min_size = .{ .width = null, .height = null }, 1871 .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, 1872 }, root_focus); 1873 1874 var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); 1875 errdefer out.deinit(); 1876 1877 if (art.getGrid()) |art_grid| { 1878 const anchor_x = switch (anchor) { 1879 .top_left => 0, 1880 .top_right => foreground.size.width -| art_grid.size.width, 1881 }; 1882 for (0..art_grid.size.height) |y| { 1883 for (0..art_grid.size.width) |x| { 1884 const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; 1885 if (src.rune == null) continue; 1886 const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; 1887 const dst = &out.cells.items[idx]; 1888 // composite the dimmed art behind every cell so it shows 1889 // through the whole UI: a blank cell becomes the art, while a 1890 // cell with a glyph keeps the glyph but takes the dimmed art as 1891 // its background (replacing whatever background it had, which 1892 // would otherwise obscure the art). 1893 if (cellIsBlank(dst.*)) { 1894 dst.* = src; 1895 dst.style.fg = sgrSafe(dimColor(dst.style.fg)); 1896 dst.style.bg = sgrSafe(dimColor(dst.style.bg)); 1897 } else { 1898 dst.style.bg = sgrSafe(dimColor(src.style.bg orelse src.style.fg)); 1899 } 1900 } 1901 } 1902 } 1903 return out; 1904 } 1905 }; 1906