╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3339 .home => |*p| .{ .home = try .init(allocator, p, session) }, 3340 .user => |*p| .{ .user = try .init(allocator, p, session) }, 3341 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 3342 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 3343 .not_found => .{ .not_found = try .init(allocator, session) }, 3344 }; 3345 3346 chooseAnsiArtForNavigation(session); 3347 3348 // on the TUI/SSH, the page sits above a one-row footer showing its web 3349 // url, when there's a web UI to point at 3350 var root = if (session.is_terminal) blk: { 3351 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 3352 errdefer box.deinit(allocator); 3353 const bg_id = bg_blk: { 3354 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 3355 errdefer background.deinit(allocator); 3356 const id = background.getFocus().id; 3357 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 3358 break :bg_blk id; 3359 }; 3360 if (session.web_url != null) { 3361 var footer = try widget.Footer.init(allocator, session); 3362 errdefer footer.deinit(allocator); 3363 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 3364 } 3365 box.getFocus().child_id = bg_id; 3366 break :blk Widget{ .box = box }; 3367 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 3368 errdefer root.deinit(allocator); 3369 3370 // input-owning views build their TextInputs in init, so reset their 3371 // registrations here 3372 session.text_inputs.clearRetainingCapacity(); 3373 3374 try root.build(allocator, .{ 3375 .min_size = .{ .width = null, .height = 40 }, 3376 .max_size = .{ .width = 100, .height = null }, 3377 }, root.getFocus()); 3378 3379 return root; 3380 } 3381 3382 // native and server-side sessions choose from the embedded collection. WASM 3383 // keeps the art serialized by the server instead. 3384 fn chooseAnsiArtForNavigation(session: *Session) void { 3385 if (comptime ansi_art.art.len == 0) return; 3386 if (session.data.current_page == .not_found) { 3387 session.data.ansi_art = ansi_art.not_found; 3388 return; 3389 } 3390 const io = session.io orelse return; 3391 var random: usize = undefined; 3392 io.random(std.mem.asBytes(&random)); 3393 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 3394 } 3395