╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3245 self.root = new_root; 3246 self.arena = arena; 3247 self.user_id = session.userId(); 3248 return true; 3249 } 3250 return false; 3251 } 3252 }; 3253 3254 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 3255 const page_widget: Widget = switch (page.*) { 3256 .home => |*p| .{ .home = try .init(allocator, p, session) }, 3257 .user => |*p| .{ .user = try .init(allocator, p, session) }, 3258 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 3259 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 3260 .not_found => .{ .not_found = try .init(allocator, session) }, 3261 }; 3262 3263 chooseAnsiArtForNavigation(session); 3264 3265 // on the TUI/SSH, the page sits above a one-row footer showing its web 3266 // url, when there's a web UI to point at 3267 var root = if (session.is_terminal) blk: { 3268 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 3269 errdefer box.deinit(allocator); 3270 const bg_id = bg_blk: { 3271 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 3272 errdefer background.deinit(allocator); 3273 const id = background.getFocus().id; 3274 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 3275 break :bg_blk id; 3276 }; 3277 if (session.web_port != null) { 3278 var footer = try widget.Footer.init(allocator, session); 3279 errdefer footer.deinit(allocator); 3280 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 3281 } 3282 box.getFocus().child_id = bg_id; 3283 break :blk Widget{ .box = box }; 3284 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 3285 errdefer root.deinit(allocator); 3286 3287 // input-owning views build their TextInputs in init, so reset their 3288 // registrations here 3289 session.text_inputs.clearRetainingCapacity(); 3290 3291 try root.build(allocator, .{ 3292 .min_size = .{ .width = null, .height = 40 }, 3293 .max_size = .{ .width = 100, .height = null }, 3294 }, root.getFocus()); 3295 3296 return root; 3297 } 3298 3299 // native and server-side sessions choose from the embedded collection. WASM 3300 // keeps the art serialized by the server instead. 3301 fn chooseAnsiArtForNavigation(session: *Session) void { 3302 if (comptime ansi_art.art.len == 0) return; 3303 if (session.data.current_page == .not_found) { 3304 session.data.ansi_art = ansi_art.not_found; 3305 return; 3306 } 3307 const io = session.io orelse return; 3308 var random: usize = undefined; 3309 io.random(std.mem.asBytes(&random)); 3310 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 3311 } 3312