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