╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2830 2831 chooseAnsiArtForNavigation(session); 2832 2833 // on the TUI/SSH, the page sits above a one-row footer showing its web 2834 // url, when there's a web UI to point at 2835 var root = if (session.is_terminal) blk: { 2836 var box = try wgt.Box(Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 2837 errdefer box.deinit(allocator); 2838 const bg_id = bg_blk: { 2839 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 2840 errdefer background.deinit(allocator); 2841 const id = background.getFocus().id; 2842 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 2843 break :bg_blk id; 2844 }; 2845 if (session.web_port != null) { 2846 var footer = try widget.Footer.init(allocator, session); 2847 errdefer footer.deinit(allocator); 2848 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 2849 } 2850 box.getFocus().child_id = bg_id; 2851 break :blk Widget{ .box = box }; 2852 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 2853 errdefer root.deinit(allocator); 2854 2855 // input-owning views build their TextInputs in init, so reset their 2856 // registrations here 2857 session.text_inputs.clearRetainingCapacity(); 2858 2859 try root.build(allocator, .{ 2860 .min_size = .{ .width = null, .height = 40 }, 2861 .max_size = .{ .width = 100, .height = null }, 2862 }, root.getFocus()); 2863 2864 return root; 2865 } 2866 2867 // native and server-side sessions choose from the embedded collection. WASM 2868 // keeps the art serialized by the server instead. 2869 fn chooseAnsiArtForNavigation(session: *Session) void { 2870 if (comptime ansi_arts.len == 0) return; 2871 const io = session.io orelse return; 2872 var random: usize = undefined; 2873 io.random(std.mem.asBytes(&random)); 2874 session.data.ansi_art = ansi_arts[random % ansi_arts.len]; 2875 } 2876