╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2521 var write_buf: [1024]u8 = undefined; 2522 var writer = output.writer(io, &write_buf); 2523 try writer.interface.print("\x1b[2J\x1b[Hcopy the following text and then press enter to go back:\r\n\r\n{s}\r\n", .{copyable_text}); 2524 try writer.interface.flush(); 2525 2526 var read_buf: [1]u8 = undefined; 2527 var reader = input.reader(io, &read_buf); 2528 while (true) { 2529 const byte = try reader.interface.takeByte(); 2530 if (byte == '\r' or byte == '\n') return; 2531 } 2532 } 2533 2534 pub fn inputKey(allocator: std.mem.Allocator, root: *Widget, key: Key, session: *Session) !void { 2535 const root_focus = root.getFocus(); 2536 const focused_before = root_focus.grandchild_id; 2537 var activate_in_page_link = false; 2538 switch (key) { 2539 // request a navigation pop; the host's Nav.sync goes back a page, or 2540 // quits when there's no history left. 2541 .escape => { 2542 session.back = .requested; 2543 return; 2544 }, 2545 .ctrl => |letter| switch (letter) { 2546 'r' => { 2547 session.refresh_requested = true; 2548 return; 2549 }, 2550 else => try root.input(allocator, key, root_focus), 2551 }, 2552 .enter => { 2553 if (root_focus.grandchild_id) |gid| { 2554 // follow a cross-page link 2555 if (crossPageLink(root_focus, gid, session.data)) |route| { 2556 return session.navigate(route); 2557 } 2558 if (rawLink(root_focus, gid)) |url| return requestRawLink(session, url); 2559 } 2560 activate_in_page_link = true; 2561 try root.input(allocator, key, root_focus); 2562 }, 2563 .mouse => |mouse| { 2564 if (mouse.action == .press and mouse.action.press == .left) { 2565 if (cellPageLink(root, mouse.x, mouse.y, session.data)) |route| return session.navigate(route); 2566 if (root_focus.hitTest(mouse.x, mouse.y)) |hit| { 2567 const focus_id = hit.id; 2568 if (hit.kind == .background) { 2569 root_focus.setFocus(focus_id); 2570 return; 2571 } 2572 if (widget.isBackButton((root_focus.children.get(focus_id) orelse return).focus)) { 2573 if (session.back == .available) session.back = .requested; 2574 return; 2575 } 2576 // follow a cross-page link 2577 if (crossPageLink(root_focus, focus_id, session.data)) |route| { 2578 return session.navigate(route); 2579 } 2580 if (currentPageLink(root_focus, focus_id, session.data)) return; 2581 if (rawLink(root_focus, focus_id)) |url| { 2582 if (!mouse.ctrl) try requestRawLink(session, url); 2583 return; 2584 } 2585 root_focus.setFocus(focus_id); 2586 activate_in_page_link = true; 2587 } 2588 // forward the press into the widget tree so buttons (and any 2589 // future click-aware widgets) can react. widgets that don't 2590 // care about presses ignore it. 2591 try root.input(allocator, key, root_focus); 2592 } else { 2593 try root.input(allocator, key, root_focus); 2594 } 2595 }, 2596 .event => |event| switch (event) { 2597 .background => |rgb| session.terminal_background = rgb, 2598 .resize => try root.input(allocator, key, root_focus), 2599 }, 2600 else => try root.input(allocator, key, root_focus), 2601 } 2602 2603 const focused_after = root_focus.grandchild_id; 2604 if (!activate_in_page_link and focused_before == focused_after) return; 2605 const focus_id = focused_after orelse return; 2606 if (inPageLink(root_focus, focus_id, session.data)) |route| session.data.current_page = route; 2607 } 2608 2609 // a link to bytes the server serves directly rather than to a page route, so 2610 // it never resolves to a RoutablePage 2611 pub const raw_link_prefix = "ax:"; 2612 2613 // a route already loaded into the current page; focusing it changes the url 2614 // without rebuilding the page 2615 pub const in_page_link_prefix = "ai:"; 2616 2617 // an in-page tab's base route, or the exact current route when it is selected 2618 pub fn inPageTabLink(session: *Session, route: RoutablePage, selected: bool) ![]const u8 { 2619 const target = if (selected) session.data.current_page else route; 2620 return session.page_arena.allocator().print("{s}{s}", .{ in_page_link_prefix, try target.toUrl(session.page_arena) }); 2621 } 2622 2623 // a button the web renderer covers with a file picker that posts the chosen 2624 // file to the url after the prefix 2625 pub const file_input_prefix = "file:"; 2626 2627 // a submit button that overrides its enclosing form's action 2628 pub const submit_action_prefix = "submit:"; 2629 2630 // one option of a radio field, as `radio:<name>=<value>` 2631 pub const radio_prefix = "radio:"; 2632 2633 // the url an `ax:` link points at, or null for anything else. a host that 2634 // suppresses the anchor's own navigation needs this to follow the link. 2635 pub fn rawLink(root_focus: *Focus, focus_id: usize) ?[]const u8 { 2636 const child = root_focus.children.get(focus_id) orelse return null; 2637 const custom = switch (child.focus.kind) { 2638 .custom => |c| c, 2639 else => return null, 2640 }; 2641 if (!std.mem.startsWith(u8, custom, raw_link_prefix)) return null; 2642 return custom[raw_link_prefix.len..]; 2643 } 2644 2645 fn requestRawLink(session: *Session, url: []const u8) !void { 2646 session.host_request = .{ .show_copyable_text = try terminalWebUrl(session.page_arena.allocator(), session, url) }; 2647 } 2648 2649 pub fn terminalWebUrl(allocator: std.mem.Allocator, session: *const Session, path: []const u8) ![]const u8 { 2650 // an absolute url is already complete 2651 if (!std.mem.startsWith(u8, path, "/")) return path; 2652 return if (session.web_port) |port| 2653 try allocator.print("http://localhost:{d}{s}", .{ port, path }) 2654 else 2655 path; 2656 } 2657 2658 // if the focus target at focus_id is an `a:` link that should navigate (a 2659 // different parent page, or a different files directory within the repo page), 2660 // return its route; otherwise null. lets a host turn a click / enter on such a 2661 // link into a navigation rather than a focus change. 2662 pub fn crossPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 2663 const current = data.current_page; 2664 const route = pageLink(root_focus, focus_id, data, "a:") orelse return null; 2665 // a link to a different parent page always navigates; within a page, a 2666 // files-directory / commits-page / list-window change navigates while tab 2667 // links stay in-page. 2668 if (route.parent() != current.parent() or RoutablePage.repoPageChanged(route, current) or RoutablePage.forkPageChanged(route, current) or RoutablePage.homePageChanged(route, current) or RoutablePage.userPageChanged(route, current)) return route; 2669 return null; 2670 } 2671 2672 // the page the clicked cell links to, from a link inside a text box's content 2673 fn cellPageLink(root: *Widget, x: usize, y: usize, data: Session.Data) ?RoutablePage { 2674 const grid = root.getGrid() orelse return null; 2675 const cell = grid.cell(x, y) catch return null; 2676 const link = cell.link orelse return null; 2677 if (link.len == 0 or link[0] != '/') return null; 2678 return if (data.host_kind == .local) RoutablePage.fromUrlLocal(link) else RoutablePage.fromUrl(link); 2679 } 2680 2681 // whether the `a:` focus target links to the page already shown, which a click 2682 // leaves alone rather than focusing 2683 pub fn currentPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) bool { 2684 const route = pageLink(root_focus, focus_id, data, "a:") orelse return false; 2685 return route.eql(data.current_page); 2686 } 2687 2688 // the route carried by an `ai:` focus target, or null for any other target 2689 pub fn inPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 2690 return pageLink(root_focus, focus_id, data, in_page_link_prefix); 2691 } 2692 2693 fn pageLink(root_focus: *Focus, focus_id: usize, data: Session.Data, prefix: []const u8) ?RoutablePage { 2694 const child = root_focus.children.get(focus_id) orelse return null; 2695 const custom = switch (child.focus.kind) { 2696 .custom => |c| c, 2697 else => return null, 2698 }; 2699 if (!std.mem.startsWith(u8, custom, prefix)) return null; 2700 const path = custom[prefix.len..]; 2701 // local sessions build (and parse) links with the repo identity elided 2702 return if (data.host_kind == .local) RoutablePage.fromUrlLocal(path) else RoutablePage.fromUrl(path); 2703 } 2704 2705 // a display author, resolved against the admin db at read time 2706 pub const Author = union(enum) { 2707 unknown, 2708 email: []const u8, // an email no user matches 2709 user_name: []const u8, 2710 2711 // the commit author line's email, resolved like initFromEmail 2712 pub fn init( 2713 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 2714 arena: *std.heap.ArenaAllocator, 2715 author_line: []const u8, 2716 ) !Author { 2717 return initFromEmail(haxy_moment, arena, evt.authorEmail(author_line)); 2718 } 2719 2720 // from a record's stored author email: it resolves to the user currently 2721 // holding it, else stays the email. the result is allocated in `arena`, 2722 // so the email may borrow transient memory. 2723 pub fn initFromEmail( 2724 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 2725 arena: *std.heap.ArenaAllocator, 2726 author_email: ?[]const u8, 2727 ) !Author { 2728 const email = author_email orelse return .unknown; 2729 if (haxy_moment) |moment| { 2730 if (try evt.User.readByEmail(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, email)) |user| { 2731 return .{ .user_name = user.name }; 2732 } 2733 } 2734 return .{ .email = try arena.allocator().dupe(u8, email) }; 2735 } 2736 }; 2737 2738 // the "a:" link to user `name`'s page. 2739 pub fn userLink(page_arena: *std.heap.ArenaAllocator, name: []const u8) ![]const u8 { 2740 const parsed = RoutablePage.Array(evt.User.name_max_len).from(name) orelse return error.RouteTooLong; 2741 const url = try (RoutablePage{ .user_repos = .{ .name = parsed } }).toUrl(page_arena); 2742 return page_arena.allocator().print("a:{s}", .{url}); 2743 } 2744 2745 // a focusable " author " box showing `author`, linking to their user page 2746 // when it is a known user 2747 pub fn authorBox(allocator: std.mem.Allocator, page_arena: *std.heap.ArenaAllocator, author: Author) !wgt.TextBox { 2748 const text = switch (author) { 2749 .unknown => "", 2750 .email, .user_name => |t| t, 2751 }; 2752 var tb = try wgt.TextBox.init(allocator, text, .{ .border = .single, .round_corners = true, .wrap_kind = .none, .top_label = .{ .text = " author " } }); 2753 errdefer tb.deinit(allocator); 2754 tb.getFocus().mode = .all; 2755 switch (author) { 2756 .user_name => |name| tb.getFocus().kind = .{ .custom = try userLink(page_arena, name) }, 2757 else => {}, 2758 } 2759 return tb; 2760 } 2761 2762 // native-TUI navigation 2763 pub const Nav = struct { 2764 root: Widget, 2765 // backs the current page (its Page data and the page-scoped strings its 2766 // widgets build). owned here, swapped on each navigation. session.page_arena 2767 // tracks whichever of these is current so widgets allocate into it. 2768 arena: *std.heap.ArenaAllocator, 2769 // the login the current root was built for 2770 user_id: ?[evt.event_id_size]u8, 2771 history: std.ArrayList(Entry), 2772 2773 // each retained page keeps its own arena, freed when the page leaves the 2774 // stack (popped on back, evicted at cap, or on deinit). this is what keeps a 2775 // long-lived session from accumulating every page it ever visited. 2776 const Entry = struct { root: Widget, route: RoutablePage, arena: *std.heap.ArenaAllocator, user_id: ?[evt.event_id_size]u8 }; 2777 2778 // cap on retained back-history so the chain can't grow memory without bound 2779 const max_history: usize = 16; 2780 2781 pub fn init(allocator: std.mem.Allocator, session: *Session) !Nav { 2782 session.back = .unavailable; 2783 const arena = try allocator.create(std.heap.ArenaAllocator); 2784 arena.* = std.heap.ArenaAllocator.init(allocator); 2785 errdefer { 2786 arena.deinit(); 2787 allocator.destroy(arena); 2788 } 2789 2790 return .{ 2791 .root = try initCurrentRoot(allocator, arena, session), 2792 .arena = arena, 2793 .user_id = session.userId(), 2794 .history = .empty, 2795 }; 2796 } 2797 2798 pub fn deinit(self: *Nav, allocator: std.mem.Allocator) void { 2799 self.root.deinit(allocator); 2800 freeArena(allocator, self.arena); 2801 for (self.history.items) |*entry| { 2802 entry.root.deinit(allocator); 2803 freeArena(allocator, entry.arena); 2804 } 2805 self.history.deinit(allocator); 2806 } 2807 2808 // rebuild the current page in place from a current moment 2809 fn rebuild(self: *Nav, allocator: std.mem.Allocator, session: *Session) !void { 2810 if (session.haxy_moment == null and session.local == null) return; 2811 const arena = try allocator.create(std.heap.ArenaAllocator); 2812 arena.* = std.heap.ArenaAllocator.init(allocator); 2813 errdefer freeArena(allocator, arena); 2814 2815 const new_root = try initCurrentRoot(allocator, arena, session); 2816 2817 self.root.deinit(allocator); 2818 freeArena(allocator, self.arena); 2819 self.root = new_root; 2820 self.arena = arena; 2821 self.user_id = session.userId(); 2822 } 2823 2824 // build the current page's root in `arena`, or the not-found page's when 2825 // the route names nothing 2826 fn initCurrentRoot(allocator: std.mem.Allocator, arena: *std.heap.ArenaAllocator, session: *Session) !Widget { 2827 session.page_arena = arena; 2828 const page = try arena.allocator().create(Page); 2829 page.* = Page.init(arena, session, session.data.current_page) catch |err| switch (err) { 2830 error.NotFound => blk: { 2831 session.data.current_page = .not_found; 2832 break :blk .not_found; 2833 }, 2834 else => |e| return e, 2835 }; 2836 return initRoot(allocator, page, session); 2837 } 2838 2839 fn freeArena(allocator: std.mem.Allocator, arena: *std.heap.ArenaAllocator) void { 2840 arena.deinit(); 2841 allocator.destroy(arena); 2842 } 2843 2844 // reconcile the displayed root with the session's navigation state. a 2845 // forward nav (current_page moved to a different parent page) pushes the 2846 // current root and builds the new page in a fresh arena; a back request 2847 // frees the current page and restores the previous one. when escape is 2848 // pressed with no history left we switch to the quit tab instead of quitting. 2849 // returns whether the root was replaced. 2850 pub fn sync(self: *Nav, allocator: std.mem.Allocator, session: *Session) !bool { 2851 // refresh: rebuild the current page in place from a current moment 2852 if (session.refresh_requested) { 2853 session.refresh_requested = false; 2854 try self.rebuild(allocator, session); 2855 return true; 2856 } 2857 2858 if (session.back == .requested) { 2859 if (self.history.pop()) |entry| { 2860 session.back = if (self.history.items.len == 0) .unavailable else .available; 2861 self.root.deinit(allocator); 2862 freeArena(allocator, self.arena); 2863 self.root = entry.root; 2864 self.arena = entry.arena; 2865 self.user_id = entry.user_id; 2866 session.page_arena = entry.arena; 2867 session.data.current_page = entry.route; 2868 // a page built under another login is rebuilt rather than restored 2869 if (!std.meta.eql(entry.user_id, session.userId())) { 2870 try self.rebuild(allocator, session); 2871 return true; 2872 } 2873 chooseAnsiArtForNavigation(session); 2874 return true; 2875 } 2876 session.back = .unavailable; 2877 // nothing to go back to; switch to the quit confirmation 2878 const root_focus = self.root.getFocus(); 2879 var iter = root_focus.children.iterator(); 2880 while (iter.next()) |entry| { 2881 switch (entry.value_ptr.focus.kind) { 2882 .custom => |custom| if (std.mem.eql(u8, custom, Quit.tab_kind)) { 2883 root_focus.setFocus(entry.key_ptr.*); 2884 // a Stack only builds its selected child, so the quit 2885 // button isn't in the focus tree until a build runs with 2886 // the quit tab selected. build once, then send a 2887 // synthetic arrow_down to drop focus from the tab onto 2888 // the button so it's ready to confirm. 2889 try self.root.build(allocator, .{ 2890 .min_size = .{ .width = null, .height = 40 }, 2891 .max_size = .{ .width = 80, .height = null }, 2892 }, root_focus); 2893 try self.root.input(allocator, .arrow_down, root_focus); 2894 break; 2895 }, 2896 else => {}, 2897 } 2898 } 2899 return false; 2900 } 2901 2902 // forward navigation: navigate() set next_page to the page to move to (a 2903 // cross-page link or tab change crossing pages) 2904 if (session.next_page) |route| { 2905 session.next_page = null; 2906 if (session.haxy_moment == null and session.local == null) return false; 2907 const previous_route = session.data.current_page; 2908 // the page we navigated to becomes the current page 2909 session.data.current_page = route; 2910 session.back = .available; 2911 2912 const arena = try allocator.create(std.heap.ArenaAllocator); 2913 arena.* = std.heap.ArenaAllocator.init(allocator); 2914 errdefer freeArena(allocator, arena); 2915 2916 const new_root = try initCurrentRoot(allocator, arena, session); 2917 2918 try self.history.append(allocator, .{ .root = self.root, .route = previous_route, .arena = self.arena, .user_id = self.user_id }); 2919 // drop the oldest entry (freeing its widget tree and arena) once over cap 2920 if (self.history.items.len > max_history) { 2921 var oldest = self.history.orderedRemove(0); 2922 oldest.root.deinit(allocator); 2923 freeArena(allocator, oldest.arena); 2924 } 2925 self.root = new_root; 2926 self.arena = arena; 2927 self.user_id = session.userId(); 2928 return true; 2929 } 2930 return false; 2931 } 2932 }; 2933 2934 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 2935 const page_widget: Widget = switch (page.*) { 2936 .home => |*p| .{ .home = try .init(allocator, p, session) }, 2937 .user => |*p| .{ .user = try .init(allocator, p, session) }, 2938 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 2939 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 2940 .not_found => .{ .not_found = try .init(allocator, session) }, 2941 }; 2942 2943 chooseAnsiArtForNavigation(session); 2944 2945 // on the TUI/SSH, the page sits above a one-row footer showing its web 2946 // url, when there's a web UI to point at 2947 var root = if (session.is_terminal) blk: { 2948 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 2949 errdefer box.deinit(allocator); 2950 const bg_id = bg_blk: { 2951 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 2952 errdefer background.deinit(allocator); 2953 const id = background.getFocus().id; 2954 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 2955 break :bg_blk id; 2956 }; 2957 if (session.web_port != null) { 2958 var footer = try widget.Footer.init(allocator, session); 2959 errdefer footer.deinit(allocator); 2960 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 2961 } 2962 box.getFocus().child_id = bg_id; 2963 break :blk Widget{ .box = box }; 2964 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 2965 errdefer root.deinit(allocator); 2966 2967 // input-owning views build their TextInputs in init, so reset their 2968 // registrations here 2969 session.text_inputs.clearRetainingCapacity(); 2970 2971 try root.build(allocator, .{ 2972 .min_size = .{ .width = null, .height = 40 }, 2973 .max_size = .{ .width = 100, .height = null }, 2974 }, root.getFocus()); 2975 2976 return root; 2977 } 2978 2979 // native and server-side sessions choose from the embedded collection. WASM 2980 // keeps the art serialized by the server instead. 2981 fn chooseAnsiArtForNavigation(session: *Session) void { 2982 if (comptime ansi_art.art.len == 0) return; 2983 if (session.data.current_page == .not_found) { 2984 session.data.ansi_art = ansi_art.not_found; 2985 return; 2986 } 2987 const io = session.io orelse return; 2988 var random: usize = undefined; 2989 io.random(std.mem.asBytes(&random)); 2990 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 2991 } 2992