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