╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2379 .min_size = .{ .width = null, .height = null }, 2380 .max_size = .{ .width = terminal.size.width, .height = terminal.size.height }, 2381 }, nav.root.getFocus()); 2382 _ = try terminal.render(&nav.root); 2383 try Repo.Events.performSync(allocator, session); 2384 }, 2385 } 2386 } 2387 2388 // persist queued actions when there's a repo; local mode has none, 2389 // so just apply in-memory 2390 if (repo_maybe) |repo| { 2391 try session.applyAndWritePending(io, allocator, repo); 2392 // reload so the next navigation builds its page from the current moment 2393 try session.reloadMoment(allocator, repo); 2394 } else { 2395 session.applyPending(); 2396 } 2397 2398 // reconcile navigation: forward to a new page, or back on escape. 2399 try nav.sync(allocator, session); 2400 2401 // the quit button (on the quit tab) asks the host to tear down. 2402 if (session.quit_requested) terminal.requestQuit(); 2403 2404 try nav.root.build(allocator, .{ 2405 .min_size = .{ .width = null, .height = null }, 2406 .max_size = .{ .width = terminal.size.width, .height = terminal.size.height }, 2407 }, nav.root.getFocus()); 2408 } 2409 } 2410 2411 fn showCopyableText(io: std.Io, copyable_text: []const u8) !void { 2412 const tty: ?std.Io.File = if (builtin.os.tag == .windows) 2413 null 2414 else 2415 try std.Io.Dir.cwd().openFile(io, "/dev/tty", .{ .mode = .read_write }); 2416 defer if (tty) |file| file.close(io); 2417 2418 const input = if (tty) |file| file else std.Io.File.stdin(); 2419 const output = if (tty) |file| file else std.Io.File.stdout(); 2420 2421 var write_buf: [1024]u8 = undefined; 2422 var writer = output.writer(io, &write_buf); 2423 try writer.interface.print("\x1b[2J\x1b[Hcopy the following text and then press enter to go back:\r\n\r\n{s}\r\n", .{copyable_text}); 2424 try writer.interface.flush(); 2425 2426 var read_buf: [1]u8 = undefined; 2427 var reader = input.reader(io, &read_buf); 2428 while (true) { 2429 const byte = try reader.interface.takeByte(); 2430 if (byte == '\r' or byte == '\n') return; 2431 } 2432 } 2433 2434 pub fn inputKey(allocator: std.mem.Allocator, root: *Widget, key: Key, session: *Session) !void { 2435 const root_focus = root.getFocus(); 2436 const focused_before = root_focus.grandchild_id; 2437 var activate_in_page_link = false; 2438 switch (key) { 2439 // request a navigation pop; the host's Nav.sync goes back a page, or 2440 // quits when there's no history left. 2441 .escape => { 2442 session.back = .requested; 2443 return; 2444 }, 2445 .ctrl => |letter| switch (letter) { 2446 'r' => { 2447 session.refresh_requested = true; 2448 return; 2449 }, 2450 else => try root.input(allocator, key, root_focus), 2451 }, 2452 .enter => { 2453 if (root_focus.grandchild_id) |gid| { 2454 // follow a cross-page link 2455 if (crossPageLink(root_focus, gid, session.data)) |route| { 2456 return session.navigate(route); 2457 } 2458 if (rawLink(root_focus, gid)) |url| return requestRawLink(session, url); 2459 } 2460 activate_in_page_link = true; 2461 try root.input(allocator, key, root_focus); 2462 }, 2463 .mouse => |mouse| { 2464 if (mouse.action == .press and mouse.action.press == .left) { 2465 if (root_focus.hitTest(mouse.x, mouse.y)) |hit| { 2466 const focus_id = hit.id; 2467 if (hit.kind == .background) { 2468 root_focus.setFocus(focus_id); 2469 return; 2470 } 2471 if (widget.isBackButton((root_focus.children.get(focus_id) orelse return).focus)) { 2472 if (session.back == .available) session.back = .requested; 2473 return; 2474 } 2475 // follow a cross-page link 2476 if (crossPageLink(root_focus, focus_id, session.data)) |route| { 2477 return session.navigate(route); 2478 } 2479 if (rawLink(root_focus, focus_id)) |url| { 2480 if (!mouse.ctrl) try requestRawLink(session, url); 2481 return; 2482 } 2483 root_focus.setFocus(focus_id); 2484 activate_in_page_link = true; 2485 } 2486 // forward the press into the widget tree so buttons (and any 2487 // future click-aware widgets) can react. widgets that don't 2488 // care about presses ignore it. 2489 try root.input(allocator, key, root_focus); 2490 } else { 2491 try root.input(allocator, key, root_focus); 2492 } 2493 }, 2494 else => try root.input(allocator, key, root_focus), 2495 } 2496 2497 const focused_after = root_focus.grandchild_id; 2498 if (!activate_in_page_link and focused_before == focused_after) return; 2499 const focus_id = focused_after orelse return; 2500 if (inPageLink(root_focus, focus_id, session.data)) |route| session.data.current_page = route; 2501 } 2502 2503 // a link to bytes the server serves directly rather than to a page route, so 2504 // it never resolves to a RoutablePage 2505 pub const raw_link_prefix = "ax:"; 2506 2507 // a route already loaded into the current page; focusing it changes the url 2508 // without rebuilding the page 2509 pub const in_page_link_prefix = "ai:"; 2510 2511 // an in-page tab's base route, or the exact current route when it is selected 2512 pub fn inPageTabLink(session: *Session, route: RoutablePage, selected: bool) ![]const u8 { 2513 const target = if (selected) session.data.current_page else route; 2514 return std.fmt.allocPrint(session.page_arena.allocator(), "{s}{s}", .{ in_page_link_prefix, try target.toUrl(session.page_arena) }); 2515 } 2516 2517 // a button the web renderer covers with a file picker that posts the chosen 2518 // file to the url after the prefix 2519 pub const file_input_prefix = "file:"; 2520 2521 // a submit button that overrides its enclosing form's action 2522 pub const submit_action_prefix = "submit:"; 2523 2524 // the url an `ax:` link points at, or null for anything else. a host that 2525 // suppresses the anchor's own navigation needs this to follow the link. 2526 pub fn rawLink(root_focus: *Focus, focus_id: usize) ?[]const u8 { 2527 const child = root_focus.children.get(focus_id) orelse return null; 2528 const custom = switch (child.focus.kind) { 2529 .custom => |c| c, 2530 else => return null, 2531 }; 2532 if (!std.mem.startsWith(u8, custom, raw_link_prefix)) return null; 2533 return custom[raw_link_prefix.len..]; 2534 } 2535 2536 fn requestRawLink(session: *Session, url: []const u8) !void { 2537 session.host_request = .{ .show_copyable_text = try terminalWebUrl(session.page_arena.allocator(), session, url) }; 2538 } 2539 2540 pub fn terminalWebUrl(allocator: std.mem.Allocator, session: *const Session, path: []const u8) ![]const u8 { 2541 // an absolute url is already complete 2542 if (!std.mem.startsWith(u8, path, "/")) return path; 2543 return if (session.web_port) |port| 2544 try std.fmt.allocPrint(allocator, "http://localhost:{d}{s}", .{ port, path }) 2545 else 2546 path; 2547 } 2548 2549 // if the focus target at focus_id is an `a:` link that should navigate (a 2550 // different parent page, or a different files directory within the repo page), 2551 // return its route; otherwise null. lets a host turn a click / enter on such a 2552 // link into a navigation rather than a focus change. 2553 pub fn crossPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 2554 const current = data.current_page; 2555 const route = pageLink(root_focus, focus_id, data, "a:") orelse return null; 2556 // a link to a different parent page always navigates; within a page, a 2557 // files-directory / commits-page / list-window change navigates while tab 2558 // links stay in-page. 2559 if (route.parent() != current.parent() or RoutablePage.repoPageChanged(route, current) or RoutablePage.forkPageChanged(route, current) or RoutablePage.homePageChanged(route, current) or RoutablePage.userPageChanged(route, current)) return route; 2560 return null; 2561 } 2562 2563 // the route carried by an `ai:` focus target, or null for any other target 2564 pub fn inPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 2565 return pageLink(root_focus, focus_id, data, in_page_link_prefix); 2566 } 2567 2568 fn pageLink(root_focus: *Focus, focus_id: usize, data: Session.Data, prefix: []const u8) ?RoutablePage { 2569 const child = root_focus.children.get(focus_id) orelse return null; 2570 const custom = switch (child.focus.kind) { 2571 .custom => |c| c, 2572 else => return null, 2573 }; 2574 if (!std.mem.startsWith(u8, custom, prefix)) return null; 2575 const path = custom[prefix.len..]; 2576 // local sessions build (and parse) links with the repo identity elided 2577 return if (data.host_kind == .local) RoutablePage.fromUrlLocal(path) else RoutablePage.fromUrl(path); 2578 } 2579 2580 // a display author, resolved against the admin db at read time 2581 pub const Author = union(enum) { 2582 unknown, 2583 email: []const u8, // an email no user matches 2584 user_name: []const u8, 2585 2586 // the commit author line's email, resolved like initFromEmail 2587 pub fn init( 2588 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 2589 arena: *std.heap.ArenaAllocator, 2590 author_line: []const u8, 2591 ) !Author { 2592 return initFromEmail(haxy_moment, arena, evt.authorEmail(author_line)); 2593 } 2594 2595 // from a record's stored author email: it resolves to the user currently 2596 // holding it, else stays the email. the result is allocated in `arena`, 2597 // so the email may borrow transient memory. 2598 pub fn initFromEmail( 2599 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 2600 arena: *std.heap.ArenaAllocator, 2601 author_email: ?[]const u8, 2602 ) !Author { 2603 const email = author_email orelse return .unknown; 2604 if (haxy_moment) |moment| { 2605 if (try evt.User.readByEmail(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, email)) |user| { 2606 return .{ .user_name = user.name }; 2607 } 2608 } 2609 return .{ .email = try arena.allocator().dupe(u8, email) }; 2610 } 2611 }; 2612 2613 // the "a:" link to user `name`'s page. 2614 pub fn userLink(page_arena: *std.heap.ArenaAllocator, name: []const u8) ![]const u8 { 2615 const parsed = RoutablePage.Array(evt.User.name_max_len).from(name) orelse return error.RouteTooLong; 2616 const url = try (RoutablePage{ .user_repos = .{ .name = parsed } }).toUrl(page_arena); 2617 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2618 } 2619 2620 // a focusable " author " box showing `author`, linking to their user page 2621 // when it is a known user 2622 pub fn authorBox(allocator: std.mem.Allocator, page_arena: *std.heap.ArenaAllocator, author: Author) !wgt.TextBox { 2623 const text = switch (author) { 2624 .unknown => "", 2625 .email, .user_name => |t| t, 2626 }; 2627 var tb = try wgt.TextBox.init(allocator, text, .{ .border_style = .single, .round_corners = true, .wrap_kind = .none, .label = " author " }); 2628 errdefer tb.deinit(allocator); 2629 tb.getFocus().mode = .all; 2630 switch (author) { 2631 .user_name => |name| tb.getFocus().kind = .{ .custom = try userLink(page_arena, name) }, 2632 else => {}, 2633 } 2634 return tb; 2635 } 2636 2637 // native-TUI navigation 2638 pub const Nav = struct { 2639 root: Widget, 2640 // backs the current page (its Page data and the page-scoped strings its 2641 // widgets build). owned here, swapped on each navigation. session.page_arena 2642 // tracks whichever of these is current so widgets allocate into it. 2643 arena: *std.heap.ArenaAllocator, 2644 history: std.ArrayList(Entry), 2645 2646 // each retained page keeps its own arena, freed when the page leaves the 2647 // stack (popped on back, evicted at cap, or on deinit). this is what keeps a 2648 // long-lived session from accumulating every page it ever visited. 2649 const Entry = struct { root: Widget, route: RoutablePage, arena: *std.heap.ArenaAllocator }; 2650 2651 // cap on retained back-history so the chain can't grow memory without bound 2652 const max_history: usize = 16; 2653 2654 pub fn init(allocator: std.mem.Allocator, session: *Session) !Nav { 2655 session.back = .unavailable; 2656 const arena = try allocator.create(std.heap.ArenaAllocator); 2657 arena.* = std.heap.ArenaAllocator.init(allocator); 2658 errdefer { 2659 arena.deinit(); 2660 allocator.destroy(arena); 2661 } 2662 2663 session.page_arena = arena; 2664 const route = session.data.current_page; 2665 2666 const page = try arena.allocator().create(Page); 2667 page.* = try Page.init(arena, session, route); 2668 return .{ 2669 .root = try initRoot(allocator, page, session), 2670 .arena = arena, 2671 .history = .empty, 2672 }; 2673 } 2674 2675 pub fn deinit(self: *Nav, allocator: std.mem.Allocator) void { 2676 self.root.deinit(allocator); 2677 freeArena(allocator, self.arena); 2678 for (self.history.items) |*entry| { 2679 entry.root.deinit(allocator); 2680 freeArena(allocator, entry.arena); 2681 } 2682 self.history.deinit(allocator); 2683 } 2684 2685 fn freeArena(allocator: std.mem.Allocator, arena: *std.heap.ArenaAllocator) void { 2686 arena.deinit(); 2687 allocator.destroy(arena); 2688 } 2689 2690 // reconcile the displayed root with the session's navigation state. a 2691 // forward nav (current_page moved to a different parent page) pushes the 2692 // current root and builds the new page in a fresh arena; a back request 2693 // frees the current page and restores the previous one. when escape is 2694 // pressed with no history left we switch to the quit tab instead of quitting. 2695 pub fn sync(self: *Nav, allocator: std.mem.Allocator, session: *Session) !void { 2696 // refresh: rebuild the current page in place from a current moment 2697 if (session.refresh_requested) { 2698 session.refresh_requested = false; 2699 if (session.haxy_moment != null or session.local != null) { 2700 const arena = try allocator.create(std.heap.ArenaAllocator); 2701 arena.* = std.heap.ArenaAllocator.init(allocator); 2702 errdefer freeArena(allocator, arena); 2703 2704 session.page_arena = arena; 2705 2706 const route = session.data.current_page; 2707 const page = try arena.allocator().create(Page); 2708 page.* = try Page.init(arena, session, route); 2709 const new_root = try initRoot(allocator, page, session); 2710 2711 self.root.deinit(allocator); 2712 freeArena(allocator, self.arena); 2713 self.root = new_root; 2714 self.arena = arena; 2715 } 2716 return; 2717 } 2718 2719 if (session.back == .requested) { 2720 if (self.history.pop()) |entry| { 2721 session.back = if (self.history.items.len == 0) .unavailable else .available; 2722 self.root.deinit(allocator); 2723 freeArena(allocator, self.arena); 2724 self.root = entry.root; 2725 self.arena = entry.arena; 2726 session.page_arena = entry.arena; 2727 session.data.current_page = entry.route; 2728 chooseAnsiArtForNavigation(session); 2729 return; 2730 } 2731 session.back = .unavailable; 2732 // nothing to go back to; switch to the quit confirmation 2733 const root_focus = self.root.getFocus(); 2734 var iter = root_focus.children.iterator(); 2735 while (iter.next()) |entry| { 2736 switch (entry.value_ptr.focus.kind) { 2737 .custom => |custom| if (std.mem.eql(u8, custom, Quit.tab_kind)) { 2738 root_focus.setFocus(entry.key_ptr.*); 2739 // a Stack only builds its selected child, so the quit 2740 // button isn't in the focus tree until a build runs with 2741 // the quit tab selected. build once, then send a 2742 // synthetic arrow_down to drop focus from the tab onto 2743 // the button so it's ready to confirm. 2744 try self.root.build(allocator, .{ 2745 .min_size = .{ .width = null, .height = 40 }, 2746 .max_size = .{ .width = 80, .height = null }, 2747 }, root_focus); 2748 try self.root.input(allocator, .arrow_down, root_focus); 2749 break; 2750 }, 2751 else => {}, 2752 } 2753 } 2754 return; 2755 } 2756 2757 // forward navigation: navigate() set next_page to the page to move to (a 2758 // cross-page link or tab change crossing pages) 2759 if (session.next_page) |route| { 2760 session.next_page = null; 2761 if (session.haxy_moment == null and session.local == null) return; 2762 const previous_route = session.data.current_page; 2763 // the page we navigated to becomes the current page 2764 session.data.current_page = route; 2765 session.back = .available; 2766 2767 const arena = try allocator.create(std.heap.ArenaAllocator); 2768 arena.* = std.heap.ArenaAllocator.init(allocator); 2769 errdefer freeArena(allocator, arena); 2770 2771 session.page_arena = arena; 2772 2773 const page = try arena.allocator().create(Page); 2774 page.* = try Page.init(arena, session, route); 2775 const new_root = try initRoot(allocator, page, session); 2776 2777 try self.history.append(allocator, .{ .root = self.root, .route = previous_route, .arena = self.arena }); 2778 // drop the oldest entry (freeing its widget tree and arena) once over cap 2779 if (self.history.items.len > max_history) { 2780 var oldest = self.history.orderedRemove(0); 2781 oldest.root.deinit(allocator); 2782 freeArena(allocator, oldest.arena); 2783 } 2784 self.root = new_root; 2785 self.arena = arena; 2786 } 2787 } 2788 }; 2789 2790 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 2791 const page_widget: Widget = switch (page.*) { 2792 .home => |*p| .{ .home = try .init(allocator, p, session) }, 2793 .user => |*p| .{ .user = try .init(allocator, p, session) }, 2794 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 2795 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 2796 }; 2797 2798 chooseAnsiArtForNavigation(session); 2799 2800 // on the TUI/SSH, the page sits above a one-row footer showing its web 2801 // url, when there's a web UI to point at 2802 var root = if (session.is_terminal) blk: { 2803 var box = try wgt.Box(Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 2804 errdefer box.deinit(allocator); 2805 const bg_id = bg_blk: { 2806 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 2807 errdefer background.deinit(allocator); 2808 const id = background.getFocus().id; 2809 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 2810 break :bg_blk id; 2811 }; 2812 if (session.web_port != null) { 2813 var footer = try widget.Footer.init(allocator, session); 2814 errdefer footer.deinit(allocator); 2815 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 2816 } 2817 box.getFocus().child_id = bg_id; 2818 break :blk Widget{ .box = box }; 2819 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 2820 errdefer root.deinit(allocator); 2821 2822 // input-owning views build their TextInputs in init, so reset their 2823 // registrations here 2824 session.text_inputs.clearRetainingCapacity(); 2825 2826 try root.build(allocator, .{ 2827 .min_size = .{ .width = null, .height = 40 }, 2828 .max_size = .{ .width = 100, .height = null }, 2829 }, root.getFocus()); 2830 2831 return root; 2832 } 2833 2834 // native and server-side sessions choose from the embedded collection. WASM 2835 // keeps the art serialized by the server instead. 2836 fn chooseAnsiArtForNavigation(session: *Session) void { 2837 if (comptime ansi_arts.len == 0) return; 2838 const io = session.io orelse return; 2839 var random: usize = undefined; 2840 io.random(std.mem.asBytes(&random)); 2841 session.data.ansi_art = ansi_arts[random % ansi_arts.len]; 2842 } 2843