╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2913 self.user_id = session.userId(); 2914 } 2915 } 2916 }; 2917 2918 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 2919 const page_widget: Widget = switch (page.*) { 2920 .home => |*p| .{ .home = try .init(allocator, p, session) }, 2921 .user => |*p| .{ .user = try .init(allocator, p, session) }, 2922 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 2923 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 2924 .not_found => .{ .not_found = try .init(allocator, session) }, 2925 }; 2926 2927 chooseAnsiArtForNavigation(session); 2928 2929 // on the TUI/SSH, the page sits above a one-row footer showing its web 2930 // url, when there's a web UI to point at 2931 var root = if (session.is_terminal) blk: { 2932 var box = try wgt.Box(Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 2933 errdefer box.deinit(allocator); 2934 const bg_id = bg_blk: { 2935 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 2936 errdefer background.deinit(allocator); 2937 const id = background.getFocus().id; 2938 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 2939 break :bg_blk id; 2940 }; 2941 if (session.web_port != null) { 2942 var footer = try widget.Footer.init(allocator, session); 2943 errdefer footer.deinit(allocator); 2944 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 2945 } 2946 box.getFocus().child_id = bg_id; 2947 break :blk Widget{ .box = box }; 2948 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 2949 errdefer root.deinit(allocator); 2950 2951 // input-owning views build their TextInputs in init, so reset their 2952 // registrations here 2953 session.text_inputs.clearRetainingCapacity(); 2954 2955 try root.build(allocator, .{ 2956 .min_size = .{ .width = null, .height = 40 }, 2957 .max_size = .{ .width = 100, .height = null }, 2958 }, root.getFocus()); 2959 2960 return root; 2961 } 2962 2963 // native and server-side sessions choose from the embedded collection. WASM 2964 // keeps the art serialized by the server instead. 2965 fn chooseAnsiArtForNavigation(session: *Session) void { 2966 if (comptime ansi_art.art.len == 0) return; 2967 if (session.data.current_page == .not_found) { 2968 session.data.ansi_art = ansi_art.not_found; 2969 return; 2970 } 2971 const io = session.io orelse return; 2972 var random: usize = undefined; 2973 io.random(std.mem.asBytes(&random)); 2974 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 2975 } 2976