╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3292 oldest.root.deinit(allocator); 3293 freeArena(allocator, oldest.arena); 3294 } 3295 self.root = new_root; 3296 self.arena = arena; 3297 self.user_id = session.userId(); 3298 return true; 3299 } 3300 return false; 3301 } 3302 }; 3303 3304 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 3305 const page_widget: Widget = switch (page.*) { 3306 .home => |*p| .{ .home = try .init(allocator, p, session) }, 3307 .user => |*p| .{ .user = try .init(allocator, p, session) }, 3308 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 3309 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 3310 .not_found => .{ .not_found = try .init(allocator, session) }, 3311 }; 3312 3313 chooseAnsiArtForNavigation(session); 3314 3315 // on the TUI/SSH, the page sits above a one-row footer showing its web 3316 // url, when there's a web UI to point at 3317 var root = if (session.is_terminal) blk: { 3318 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 3319 errdefer box.deinit(allocator); 3320 const bg_id = bg_blk: { 3321 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 3322 errdefer background.deinit(allocator); 3323 const id = background.getFocus().id; 3324 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 3325 break :bg_blk id; 3326 }; 3327 if (session.web_port != null) { 3328 var footer = try widget.Footer.init(allocator, session); 3329 errdefer footer.deinit(allocator); 3330 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 3331 } 3332 box.getFocus().child_id = bg_id; 3333 break :blk Widget{ .box = box }; 3334 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 3335 errdefer root.deinit(allocator); 3336 3337 // input-owning views build their TextInputs in init, so reset their 3338 // registrations here 3339 session.text_inputs.clearRetainingCapacity(); 3340 3341 try root.build(allocator, .{ 3342 .min_size = .{ .width = null, .height = 40 }, 3343 .max_size = .{ .width = 100, .height = null }, 3344 }, root.getFocus()); 3345 3346 return root; 3347 } 3348 3349 // native and server-side sessions choose from the embedded collection. WASM 3350 // keeps the art serialized by the server instead. 3351 fn chooseAnsiArtForNavigation(session: *Session) void { 3352 if (comptime ansi_art.art.len == 0) return; 3353 if (session.data.current_page == .not_found) { 3354 session.data.ansi_art = ansi_art.not_found; 3355 return; 3356 } 3357 const io = session.io orelse return; 3358 var random: usize = undefined; 3359 io.random(std.mem.asBytes(&random)); 3360 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 3361 } 3362