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