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