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