╭ changed ────╮ │build.zig.zon│ ╰─────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 3 .version = "0.0.0", │ │ 4 .dependencies = .{ │ │ 5 .xit = .{ │ │ 6 - .url = "git+https://github.com/xit-vcs/xit#335bfaefb4a99c34156f9282ea97a45c45040321",│ │ 7 - .hash = "xit-0.0.0-Ub3nDLTjTwE_Rf543BJ0rgO_LwZgWWWY9qRsKYxqMCqu", │ │ 6 + .url = "git+https://github.com/xit-vcs/xit#125858711049dc26dbdd96da2d780aa1e7b61d5a",│ │ 7 + .hash = "xit-0.0.0-Ub3nDLTjTwGhPG74urz2RWgJpTxUOZuJlXv8EewpgGTh", │ │ 8 }, │ │ 9 }, │ │10 .paths = .{ │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ───────────╮ │src/embed/index.html│ ╰────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────╮ │ 7 html { │ │ 8 background-color: rgba(0, 50, 70, 1.0); │ │ 9 color: rgba(200, 200, 200, 1.0); │ │10 + /* the grid's inline-block cell-runs can render a few pixels wider │ │11 + than the column width, so prevent spurious horiz scrollbar */ │ │12 + overflow-x: hidden; │ │13 + /* always reserve the vertical scrollbar's space so the usable width│ │14 + is constant whether or not it's showing */ │ │15 + scrollbar-gutter: stable; │ │16 } │ │17 │ │18 @font-face { │ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────╮ │29 │ │30 #grid { │ │31 white-space: pre; │ │32 + } │ │33 + │ │34 + /* render each colored cell-run as an inline-block to prevent│ │35 + horizontal seams between rows of the block art. */ │ │36 + #grid span { │ │37 + display: inline-block; │ │38 + vertical-align: top; │ │39 } │ │40 │ │41 /* overlay elements share the grid's coordinate system since │ ╰───────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────╮ │53 │ │54 .page input { │ │55 color: inherit; │ │43 - background: rgba(0, 50, 70, 1.0); │ │56 + /* transparent field so the backdrop shows through fully; a dark│ │57 + halo backs just the characters so they stay legible */ │ │58 + background: transparent; │ │59 + text-shadow: 0 0 3px #000, 0 0 5px #000, 0 0 5px #000; │ │60 border: none; │ │61 } │ │62 │ ╰────────────────────────────────────────────────────────────────────────────────╯ ╭ added ────────────╮ │src/embed/demon.ans│ ╰───────────────────╯ ╭ changed ─╮ │src/ui.zig│ ╰──────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────╮ │169 } │ │170 │ │171 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { │ │172 - var root: Widget = switch (page.*) { │ │172 + const page_widget: Widget = switch (page.*) { │ │173 .home => |*p| .{ .home = try .init(allocator, p, session) }, │ │174 }; │ │175 + │ │176 + const demon_art = @embedFile("embed/demon.ans"); │ │177 + │ │178 + var root = Widget{ .background = try AnsiBackground.init(allocator, page_widget, demon_art) };│ │179 errdefer root.deinit(allocator); │ │180 │ │181 try root.build(allocator, .{ │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────╮ │199 flow_box: FlowBox, │ │200 spacer: Spacer, │ │201 center: Center, │ │202 + ansi_art: AnsiArt, │ │203 + background: AnsiBackground, │ │204 home: Home.View, │ │205 title: Title.View, │ │206 home_header: Home.Header.View,│ ╰───────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │650 return &self.focus; │ │651 } │ │652 }; │ │653 + │ │654 +// renders truecolor ANSI art │ │655 +pub const AnsiArt = struct { │ │656 + focus: Focus, │ │657 + grid: ?Grid, │ │658 + content: []const u8, │ │659 + │ │660 + pub fn init(content: []const u8) AnsiArt { │ │661 + return .{ │ │662 + .focus = Focus.init(.container), │ │663 + .grid = null, │ │664 + .content = content, │ │665 + }; │ │666 + } │ │667 + │ │668 + pub fn deinit(self: *AnsiArt, allocator: std.mem.Allocator) void { │ │669 + self.focus.deinit(allocator); │ │670 + if (self.grid) |*grid| { │ │671 + grid.deinit(); │ │672 + self.grid = null; │ │673 + } │ │674 + } │ │675 + │ │676 + pub fn build(self: *AnsiArt, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { │ │677 + _ = root_focus; │ │678 + self.clearGrid(); │ │679 + │ │680 + // parse into rows of cells, then copy into a rectangular grid │ │681 + var rows: std.ArrayList(std.ArrayList(Grid.Cell)) = .empty; │ │682 + defer { │ │683 + for (rows.items) |*row| row.deinit(allocator); │ │684 + rows.deinit(allocator); │ │685 + } │ │686 + var row: std.ArrayList(Grid.Cell) = .empty; │ │687 + errdefer row.deinit(allocator); │ │688 │ │689 + var style: Grid.Style = .{}; │ │690 + var width: usize = 0; │ │691 + const content = self.content; │ │692 + var i: usize = 0; │ │693 + while (i < content.len) { │ │694 + const byte = content[i]; │ │695 + if (byte == '\n') { │ │696 + width = @max(width, row.items.len); │ │697 + try rows.append(allocator, row); │ │698 + row = .empty; │ │699 + i += 1; │ │700 + } else if (byte == 0x1B and i + 1 < content.len and content[i + 1] == '[') { │ │701 + // CSI: scan to the final byte (0x40..0x7E); apply it if it's 'm' │ │702 + var j = i + 2; │ │703 + while (j < content.len and !(content[j] >= 0x40 and content[j] <= 0x7E)) j += 1; │ │704 + if (j >= content.len) { │ │705 + i = content.len; // malformed trailing escape; stop │ │706 + } else { │ │707 + if (content[j] == 'm') applySgr(&style, content[i + 2 .. j]); │ │708 + i = j + 1; │ │709 + } │ │710 + } else { │ │711 + const len = std.unicode.utf8ByteSequenceLength(byte) catch 1; │ │712 + const end = @min(content.len, i + len); │ │713 + const rune = content[i..end]; │ │714 + const transparent = end - i == 1 and rune[0] == ' ' and │ │715 + style.fg == null and style.bg == null and !style.inverted; │ │716 + try row.append(allocator, .{ │ │717 + .rune = if (transparent) null else rune, │ │718 + .style = style, │ │719 + }); │ │720 + i = end; │ │721 + } │ │722 + } │ │723 + // a trailing row with content but no closing newline │ │724 + if (row.items.len > 0) { │ │725 + width = @max(width, row.items.len); │ │726 + try rows.append(allocator, row); │ │727 + } else { │ │728 + row.deinit(allocator); │ │729 + } │ │730 + row = .empty; // ownership moved into rows (or freed); keep errdefer safe │ │731 + │ │732 + const height = rows.items.len; │ │733 + if (width == 0 or height == 0) return; │ │734 + │ │735 + const clamped_w = @min(width, constraint.max_size.width orelse width); │ │736 + const clamped_h = @min(height, constraint.max_size.height orelse height); │ │737 + │ │738 + var grid = try Grid.init(allocator, .{ .width = clamped_w, .height = clamped_h }); │ │739 + errdefer grid.deinit(); │ │740 + for (rows.items[0..clamped_h], 0..) |r, y| { │ │741 + const n = @min(r.items.len, clamped_w); │ │742 + for (r.items[0..n], 0..) |cell, x| { │ │743 + grid.cells.items[try grid.cells.at(.{ y, x })] = cell; │ │744 + } │ │745 + } │ │746 + self.grid = grid; │ │747 + } │ │748 + │ │749 + pub fn input(self: *AnsiArt, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { │ │750 + _ = self; │ │751 + _ = allocator; │ │752 + _ = key; │ │753 + _ = root_focus; │ │754 + } │ │755 + │ │756 + pub fn clearGrid(self: *AnsiArt) void { │ │757 + if (self.grid) |*grid| { │ │758 + grid.deinit(); │ │759 + self.grid = null; │ │760 + } │ │761 + } │ │762 + │ │763 + pub fn getGrid(self: AnsiArt) ?Grid { │ │764 + return self.grid; │ │765 + } │ │766 + │ │767 + pub fn getFocus(self: *AnsiArt) *Focus { │ │768 + return &self.focus; │ │769 + } │ │770 + │ │771 + fn applySgr(style: *Grid.Style, params: []const u8) void { │ │772 + var nums: [16]u32 = undefined; │ │773 + var n: usize = 0; │ │774 + var it = std.mem.splitScalar(u8, params, ';'); │ │775 + while (it.next()) |tok| { │ │776 + if (n >= nums.len) break; │ │777 + // an empty parameter (e.g. bare "\x1b[m") means 0 │ │778 + nums[n] = std.fmt.parseInt(u32, tok, 10) catch 0; │ │779 + n += 1; │ │780 + } │ │781 + if (n == 0) { │ │782 + style.* = .{}; │ │783 + return; │ │784 + } │ │785 + var i: usize = 0; │ │786 + while (i < n) : (i += 1) { │ │787 + switch (nums[i]) { │ │788 + 0 => style.* = .{}, │ │789 + 7 => style.inverted = true, │ │790 + 27 => style.inverted = false, │ │791 + 39 => style.fg = null, │ │792 + 49 => style.bg = null, │ │793 + 38, 48 => { │ │794 + // truecolor form: 38;2;r;g;b — anything else is ignored │ │795 + if (i + 4 < n and nums[i + 1] == 2) { │ │796 + const c = Grid.Color{ │ │797 + .r = @truncate(nums[i + 2]), │ │798 + .g = @truncate(nums[i + 3]), │ │799 + .b = @truncate(nums[i + 4]), │ │800 + }; │ │801 + if (nums[i] == 38) style.fg = c else style.bg = c; │ │802 + i += 4; │ │803 + } │ │804 + }, │ │805 + else => {}, │ │806 + } │ │807 + } │ │808 + } │ │809 +}; │ │810 + │ │811 +// a full-screen wrapper that renders ANSI art behind whatever page it wraps │ │812 +pub const AnsiBackground = struct { │ │813 + grid: ?Grid, │ │814 + child: *Widget, │ │815 + art: AnsiArt, │ │816 + │ │817 + pub fn init(allocator: std.mem.Allocator, child_widget: Widget, art_content: []const u8) !AnsiBackground { │ │818 + var cw = child_widget; │ │819 + const child = allocator.create(Widget) catch |e| { │ │820 + cw.deinit(allocator); │ │821 + return e; │ │822 + }; │ │823 + child.* = cw; │ │824 + return .{ .grid = null, .child = child, .art = AnsiArt.init(art_content) }; │ │825 + } │ │826 + │ │827 + pub fn deinit(self: *AnsiBackground, allocator: std.mem.Allocator) void { │ │828 + if (self.grid) |*grid| grid.deinit(); │ │829 + self.art.deinit(allocator); │ │830 + self.child.deinit(allocator); │ │831 + allocator.destroy(self.child); │ │832 + } │ │833 + │ │834 + pub fn build(self: *AnsiBackground, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void {│ │835 + self.clearGrid(); │ │836 + │ │837 + // make the wrapped page fill the whole available area │ │838 + try self.child.build(allocator, .{ │ │839 + .min_size = .{ │ │840 + .width = constraint.max_size.width orelse constraint.min_size.width, │ │841 + .height = constraint.max_size.height orelse constraint.min_size.height, │ │842 + }, │ │843 + .max_size = constraint.max_size, │ │844 + }, root_focus); │ │845 + │ │846 + if (self.child.getGrid()) |fg| { │ │847 + self.grid = try artBehind(allocator, fg, &self.art, .top_right, root_focus); │ │848 + } │ │849 + } │ │850 + │ │851 + pub fn input(self: *AnsiBackground, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { │ │852 + try self.child.input(allocator, key, root_focus); │ │853 + } │ │854 + │ │855 + pub fn clearGrid(self: *AnsiBackground) void { │ │856 + if (self.grid) |*grid| { │ │857 + grid.deinit(); │ │858 + self.grid = null; │ │859 + } │ │860 + self.child.clearGrid(); │ │861 + self.art.clearGrid(); │ │862 + } │ │863 + │ │864 + pub fn getGrid(self: AnsiBackground) ?Grid { │ │865 + return self.grid orelse self.child.getGrid(); │ │866 + } │ │867 + │ │868 + pub fn getFocus(self: *AnsiBackground) *Focus { │ │869 + return self.child.getFocus(); │ │870 + } │ │871 + │ │872 + // which top corner the art hugs. │ │873 + const ArtAnchor = enum { top_left, top_right }; │ │874 + │ │875 + // a foreground cell counts as blank if it's empty or a bare space without styling │ │876 + fn cellIsBlank(cell: Grid.Cell) bool { │ │877 + if (cell.rune) |rune| { │ │878 + return std.mem.eql(u8, rune, " ") and │ │879 + cell.style.fg == null and cell.style.bg == null and !cell.style.inverted; │ │880 + } │ │881 + return true; │ │882 + } │ │883 + │ │884 + // a single representative color for an art cell │ │885 + fn artCellColor(style: Grid.Style) ?Grid.Color { │ │886 + const f = style.fg orelse return style.bg; │ │887 + const b = style.bg orelse return f; │ │888 + return .{ │ │889 + .r = @intCast((@as(u16, f.r) + b.r) / 2), │ │890 + .g = @intCast((@as(u16, f.g) + b.g) / 2), │ │891 + .b = @intCast((@as(u16, f.b) + b.b) / 2), │ │892 + }; │ │893 + } │ │894 + │ │895 + // behind a visible glyph the art color is dimmed to this fraction of its │ │896 + // brightness so light terminal text stays legible on top of it │ │897 + const glyph_bg_brightness = 45; // percent │ │898 + │ │899 + // a glyph sitting over the art also gets its foreground pinned to this color │ │900 + // (unless it set its own), so the text stays legible │ │901 + const glyph_fg_over_art = Grid.Color{ .r = 235, .g = 235, .b = 235 }; │ │902 + │ │903 + fn dimColor(color: ?Grid.Color) ?Grid.Color { │ │904 + const c = color orelse return null; │ │905 + return .{ │ │906 + .r = @intCast(@as(u16, c.r) * glyph_bg_brightness / 100), │ │907 + .g = @intCast(@as(u16, c.g) * glyph_bg_brightness / 100), │ │908 + .b = @intCast(@as(u16, c.b) * glyph_bg_brightness / 100), │ │909 + }; │ │910 + } │ │911 + │ │912 + // composites ANSI art behind a foreground grid │ │913 + fn artBehind(allocator: std.mem.Allocator, foreground: Grid, art: *AnsiArt, anchor: ArtAnchor, root_focus: *Focus) !Grid { │ │914 + art.clearGrid(); │ │915 + try art.build(allocator, .{ │ │916 + .min_size = .{ .width = null, .height = null }, │ │917 + .max_size = .{ .width = foreground.size.width, .height = foreground.size.height }, │ │918 + }, root_focus); │ │919 + │ │920 + var out = try Grid.initFromGrid(allocator, foreground, foreground.size, 0, 0); │ │921 + errdefer out.deinit(); │ │922 + │ │923 + if (art.getGrid()) |art_grid| { │ │924 + const anchor_x = switch (anchor) { │ │925 + .top_left => 0, │ │926 + .top_right => foreground.size.width -| art_grid.size.width, │ │927 + }; │ │928 + for (0..art_grid.size.height) |y| { │ │929 + for (0..art_grid.size.width) |x| { │ │930 + const src = art_grid.cells.items[try art_grid.cells.at(.{ y, x })]; │ │931 + if (src.rune == null) continue; │ │932 + const idx = out.cells.at(.{ y, anchor_x + x }) catch continue; │ │933 + const dst = &out.cells.items[idx]; │ │934 + if (cellIsBlank(dst.*)) { │ │935 + dst.* = src; │ │936 + } else if (dst.style.bg == null) { │ │937 + dst.style.bg = dimColor(artCellColor(src.style)); │ │938 + if (dst.style.fg == null) dst.style.fg = glyph_fg_over_art; │ │939 + } │ │940 + } │ │941 + } │ │942 + } │ │943 + return out; │ │944 + } │ │945 +}; │ │946 + │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────────────╮ │src/ui/Home/Auth/Login.zig│ ╰──────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │50 var nav_ids: [3]usize = undefined; │ │51 │ │52 { │ │53 - var username = wgt.TextInput(ui.Widget).init(.{ .label = " username ", .name = "username", .rounded_corners = true }); │ │53 + var username = wgt.TextInput(ui.Widget).init(.{ .label = " username ", .name = "username", .rounded_corners = true, .render_content = !wasm });│ │54 errdefer username.deinit(allocator); │ │55 username.getFocus().focusable = true; │ │56 nav_ids[username_index] = username.getFocus().id; │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │62 } │ │63 │ │64 { │ │65 - var password = wgt.TextInput(ui.Widget).init(.{ .label = " password ", .password = true, .name = "password", .rounded_corners = true }); │ │65 + var password = wgt.TextInput(ui.Widget).init(.{ .label = " password ", .password = true, .name = "password", .rounded_corners = true, .render_content = !wasm });│ │66 errdefer password.deinit(allocator); │ │67 password.getFocus().focusable = true; │ │68 nav_ids[password_index] = password.getFocus().id; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯