╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2940 } 2941 }, 2942 .event => |event| switch (event) { 2943 .background => |rgb| session.terminal_background = rgb, 2944 .resize => try root.input(allocator, key, root_focus), 2945 }, 2946 // a scroll tick goes to the pane under the pointer, focusing it first. 2947 // from outside any pane (the tabs, a sub-header) or from a text input 2948 // it moves like the arrows instead, so scrolling up from a search box 2949 // reaches the header and stops there. 2950 .scroll_up, .scroll_down => |position| { 2951 if (focusedPane(root_focus)) |pane| if (scrollUnder(root_focus, position)) |under| { 2952 if (under != pane) root_focus.setFocus(under); 2953 }; 2954 try root.input(allocator, key, root_focus); 2955 }, 2956 else => try root.input(allocator, key, root_focus), 2957 } 2958 2959 const focused_after = root_focus.grandchild_id; 2960 if (!activate_in_page_link and focused_before == focused_after) return; 2961 const focus_id = focused_after orelse return; 2962 if (inPageLink(root_focus, focus_id, session.data)) |route| session.data.current_page = route; 2963 } 2964 2965 // the innermost vertically scrolling widget laid out under `position` 2966 fn scrollUnder(root_focus: *const Focus, position: xitui.input.Position) ?usize { 2967 var found: ?usize = null; 2968 var found_area: usize = std.math.maxInt(usize); 2969 var iter = root_focus.children.iterator(); 2970 while (iter.next()) |entry| { 2971 const info = entry.value_ptr.focus.scroll orelse continue; 2972 if (info.direction == .horiz) continue; 2973 const r = entry.value_ptr.rect; 2974 if (position.x < r.x or position.y < r.y or position.x >= r.x + r.size.width or position.y >= r.y + r.size.height) continue; 2975 // a nested scroll lies within its parent, so the smallest is innermost 2976 const area = r.size.width * r.size.height; 2977 if (area < found_area) { 2978 found = entry.key_ptr.*; 2979 found_area = area; 2980 } 2981 } 2982 return found; 2983 } 2984 2985 // the innermost vertically scrolling widget the focus lies in, unless the 2986 // focused widget is a text input 2987 fn focusedPane(root_focus: *const Focus) ?usize { 2988 var current = root_focus.grandchild_id orelse return null; 2989 switch ((root_focus.children.get(current) orelse return null).focus.kind) { 2990 .text_input, .text_input_password, .text_area => return null, 2991 else => {}, 2992 } 2993 while (root_focus.children.get(current)) |child| { 2994 if (child.focus.scroll) |info| if (info.direction != .horiz) return current; 2995 current = child.parent_id; 2996 } 2997 return null; 2998 } 2999 3000 // a link to bytes the server serves directly rather than to a page route, so 3001 // it never resolves to a RoutablePage 3002 pub const raw_link_prefix = "ax:"; 3003 3004 // a route already loaded into the current page; focusing it changes the url 3005 // without rebuilding the page 3006 pub const in_page_link_prefix = "ai:"; 3007 3008 // an in-page tab's base route, or the exact current route when it is selected 3009 pub fn inPageTabLink(session: *Session, route: RoutablePage, selected: bool) ![]const u8 { 3010 const target = if (selected) session.data.current_page else route; 3011 return session.page_arena.allocator().print("{s}{s}", .{ in_page_link_prefix, try target.toUrl(session.page_arena) }); 3012 } 3013 3014 // a button the web renderer covers with a file picker that posts the chosen 3015 // file to the url after the prefix 3016 pub const file_input_prefix = "file:"; 3017 3018 // a submit button that overrides its enclosing form's action 3019 pub const submit_action_prefix = "submit:"; 3020 3021 // one option of a radio field, as `radio:<name>=<value>` 3022 pub const radio_prefix = "radio:"; 3023 3024 // the url an `ax:` link points at, or null for anything else. a host that 3025 // suppresses the anchor's own navigation needs this to follow the link. 3026 pub fn rawLink(root_focus: *Focus, focus_id: usize) ?[]const u8 { 3027 const child = root_focus.children.get(focus_id) orelse return null; 3028 const custom = switch (child.focus.kind) { 3029 .custom => |c| c, 3030 else => return null, 3031 }; 3032 if (!std.mem.startsWith(u8, custom, raw_link_prefix)) return null; 3033 return custom[raw_link_prefix.len..]; 3034 } 3035 3036 fn requestRawLink(session: *Session, url: []const u8) !void { 3037 session.host_request = .{ .show_copyable_text = try terminalWebUrl(session.page_arena.allocator(), session, url) }; 3038 } 3039 3040 pub fn terminalWebUrl(allocator: std.mem.Allocator, session: *const Session, path: []const u8) ![]const u8 { 3041 // an absolute url is already complete 3042 if (!std.mem.startsWith(u8, path, "/")) return path; 3043 return if (session.web_url) |web_url| 3044 try allocator.print("{s}{s}", .{ web_url, path }) 3045 else 3046 path; 3047 } 3048 3049 // if the focus target at focus_id is an `a:` link that should navigate (a 3050 // different parent page, or a different files directory within the repo page), 3051 // return its route; otherwise null. lets a host turn a click / enter on such a 3052 // link into a navigation rather than a focus change. 3053 pub fn crossPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 3054 const current = data.current_page; 3055 const route = pageLink(root_focus, focus_id, data, "a:") orelse return null; 3056 // a link to a different parent page always navigates; within a page, a 3057 // files-directory / commits-page / list-window change navigates while tab 3058 // links stay in-page. 3059 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; 3060 return null; 3061 } 3062 3063 // the page the clicked cell links to, from a link inside a text box's content 3064 fn cellPageLink(root: *Widget, x: usize, y: usize, data: Session.Data) ?RoutablePage { 3065 const grid = root.getGrid() orelse return null; 3066 const cell = grid.cell(x, y) catch return null; 3067 const link = cell.link orelse return null; 3068 if (link.len == 0 or link[0] != '/') return null; 3069 return if (data.host_kind == .local) RoutablePage.fromUrlLocal(link) else RoutablePage.fromUrl(link); 3070 } 3071 3072 // whether the `a:` focus target links to the page already shown, which a click 3073 // leaves alone rather than focusing 3074 pub fn currentPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) bool { 3075 const route = pageLink(root_focus, focus_id, data, "a:") orelse return false; 3076 return route.eql(data.current_page); 3077 } 3078 3079 // the route carried by an `ai:` focus target, or null for any other target 3080 pub fn inPageLink(root_focus: *Focus, focus_id: usize, data: Session.Data) ?RoutablePage { 3081 return pageLink(root_focus, focus_id, data, in_page_link_prefix); 3082 } 3083 3084 fn pageLink(root_focus: *Focus, focus_id: usize, data: Session.Data, prefix: []const u8) ?RoutablePage { 3085 const child = root_focus.children.get(focus_id) orelse return null; 3086 const custom = switch (child.focus.kind) { 3087 .custom => |c| c, 3088 else => return null, 3089 }; 3090 if (!std.mem.startsWith(u8, custom, prefix)) return null; 3091 const path = custom[prefix.len..]; 3092 // local sessions build (and parse) links with the repo identity elided 3093 return if (data.host_kind == .local) RoutablePage.fromUrlLocal(path) else RoutablePage.fromUrl(path); 3094 } 3095 3096 // an assignee as the detail view shows it: the stored email, and the name of 3097 // the user holding it on this instance when there is one 3098 pub const Assignee = struct { 3099 email: []const u8, 3100 name: ?[]const u8 = null, 3101 3102 pub fn display(self: Assignee) []const u8 { 3103 return self.name orelse self.email; 3104 } 3105 }; 3106 3107 // a display author, resolved against the admin db at read time 3108 pub const Author = union(enum) { 3109 unknown, 3110 email: []const u8, // an email no user matches 3111 user_name: []const u8, 3112 3113 // the commit author line's email, resolved like initFromEmail 3114 pub fn init( 3115 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 3116 arena: *std.heap.ArenaAllocator, 3117 author_line: []const u8, 3118 ) !Author { 3119 return initFromEmail(haxy_moment, arena, evt.authorEmail(author_line)); 3120 } 3121 3122 // from a record's stored author email: it resolves to the user currently 3123 // holding it, else stays the email. the result is allocated in `arena`, 3124 // so the email may borrow transient memory. 3125 pub fn initFromEmail( 3126 haxy_moment: ?evt.AdminDB.HashMap(.read_only), 3127 arena: *std.heap.ArenaAllocator, 3128 author_email: ?[]const u8, 3129 ) !Author { 3130 const email = author_email orelse return .unknown; 3131 if (haxy_moment) |moment| { 3132 if (try evt.User.readByEmail(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, email)) |user| { 3133 return .{ .user_name = user.name }; 3134 } 3135 } 3136 return .{ .email = try arena.allocator().dupe(u8, email) }; 3137 } 3138 }; 3139 3140 // the "a:" link to user `name`'s page. 3141 pub fn userLink(page_arena: *std.heap.ArenaAllocator, name: []const u8) ![]const u8 { 3142 const parsed = RoutablePage.Array(evt.User.name_max_len).from(name) orelse return error.RouteTooLong; 3143 const url = try (RoutablePage{ .user_repos = .{ .name = parsed } }).toUrl(page_arena); 3144 return page_arena.allocator().print("a:{s}", .{url}); 3145 } 3146 3147 // a focusable " author " box showing `author`, linking to their user page 3148 // when it is a known user 3149 pub fn authorBox(allocator: std.mem.Allocator, page_arena: *std.heap.ArenaAllocator, author: Author) !wgt.TextBox { 3150 const text = switch (author) { 3151 .unknown => "", 3152 .email, .user_name => |t| t, 3153 }; 3154 var tb = try wgt.TextBox.init(allocator, text, .{ .border = .single, .round_corners = true, .wrap_kind = .none, .top_label = .{ .text = " author " } }); 3155 errdefer tb.deinit(allocator); 3156 tb.getFocus().mode = .all; 3157 switch (author) { 3158 .user_name => |name| tb.getFocus().kind = .{ .custom = try userLink(page_arena, name) }, 3159 else => {}, 3160 } 3161 return tb; 3162 } 3163 3164 // native-TUI navigation 3165 pub const Nav = struct { 3166 root: Widget, 3167 // backs the current page (its Page data and the page-scoped strings its 3168 // widgets build). owned here, swapped on each navigation. session.page_arena 3169 // tracks whichever of these is current so widgets allocate into it. 3170 arena: *std.heap.ArenaAllocator, 3171 // the login the current root was built for 3172 user_id: ?[evt.event_id_size]u8, 3173 history: std.ArrayList(Entry), 3174 3175 // each retained page keeps its own arena, freed when the page leaves the 3176 // stack (popped on back, evicted at cap, or on deinit). this is what keeps a 3177 // long-lived session from accumulating every page it ever visited. 3178 const Entry = struct { root: Widget, route: RoutablePage, arena: *std.heap.ArenaAllocator, user_id: ?[evt.event_id_size]u8 }; 3179 3180 // cap on retained back-history so the chain can't grow memory without bound 3181 const max_history: usize = 16; 3182 3183 pub fn init(allocator: std.mem.Allocator, session: *Session) !Nav { 3184 session.back = .unavailable; 3185 const arena = try allocator.create(std.heap.ArenaAllocator); 3186 arena.* = std.heap.ArenaAllocator.init(allocator); 3187 errdefer { 3188 arena.deinit(); 3189 allocator.destroy(arena); 3190 } 3191 3192 return .{ 3193 .root = try initCurrentRoot(allocator, arena, session), 3194 .arena = arena, 3195 .user_id = session.userId(), 3196 .history = .empty, 3197 }; 3198 } 3199 3200 pub fn deinit(self: *Nav, allocator: std.mem.Allocator) void { 3201 self.root.deinit(allocator); 3202 freeArena(allocator, self.arena); 3203 for (self.history.items) |*entry| { 3204 entry.root.deinit(allocator); 3205 freeArena(allocator, entry.arena); 3206 } 3207 self.history.deinit(allocator); 3208 } 3209 3210 // rebuild the current page in place from a current moment 3211 fn rebuild(self: *Nav, allocator: std.mem.Allocator, session: *Session) !void { 3212 if (session.haxy_moment == null and session.local == null) return; 3213 const arena = try allocator.create(std.heap.ArenaAllocator); 3214 arena.* = std.heap.ArenaAllocator.init(allocator); 3215 errdefer freeArena(allocator, arena); 3216 3217 const new_root = try initCurrentRoot(allocator, arena, session); 3218 3219 self.root.deinit(allocator); 3220 freeArena(allocator, self.arena); 3221 self.root = new_root; 3222 self.arena = arena; 3223 self.user_id = session.userId(); 3224 } 3225 3226 // build the current page's root in `arena`, or the not-found page's when 3227 // the route names nothing 3228 fn initCurrentRoot(allocator: std.mem.Allocator, arena: *std.heap.ArenaAllocator, session: *Session) !Widget { 3229 session.page_arena = arena; 3230 const page = try arena.allocator().create(Page); 3231 page.* = Page.init(arena, session, session.data.current_page) catch |err| switch (err) { 3232 error.NotFound => blk: { 3233 session.data.current_page = .not_found; 3234 break :blk .not_found; 3235 }, 3236 else => |e| return e, 3237 }; 3238 return initRoot(allocator, page, session); 3239 } 3240 3241 fn freeArena(allocator: std.mem.Allocator, arena: *std.heap.ArenaAllocator) void { 3242 arena.deinit(); 3243 allocator.destroy(arena); 3244 } 3245 3246 // reconcile the displayed root with the session's navigation state. a 3247 // forward nav (current_page moved to a different parent page) pushes the 3248 // current root and builds the new page in a fresh arena; a back request 3249 // frees the current page and restores the previous one. when escape is 3250 // pressed with no history left we switch to the quit tab instead of quitting. 3251 // returns whether the root was replaced. 3252 pub fn sync(self: *Nav, allocator: std.mem.Allocator, session: *Session) !bool { 3253 // refresh: rebuild the current page in place from a current moment 3254 if (session.refresh_requested) { 3255 session.refresh_requested = false; 3256 try self.rebuild(allocator, session); 3257 return true; 3258 } 3259 3260 if (session.back == .requested) { 3261 if (self.history.pop()) |entry| { 3262 session.back = if (self.history.items.len == 0) .unavailable else .available; 3263 self.root.deinit(allocator); 3264 freeArena(allocator, self.arena); 3265 self.root = entry.root; 3266 self.arena = entry.arena; 3267 self.user_id = entry.user_id; 3268 session.page_arena = entry.arena; 3269 session.data.current_page = entry.route; 3270 // a page built under another login is rebuilt rather than restored 3271 if (!std.meta.eql(entry.user_id, session.userId())) { 3272 try self.rebuild(allocator, session); 3273 return true; 3274 } 3275 chooseAnsiArtForNavigation(session); 3276 return true; 3277 } 3278 session.back = .unavailable; 3279 // nothing to go back to; switch to the quit confirmation 3280 const root_focus = self.root.getFocus(); 3281 var iter = root_focus.children.iterator(); 3282 while (iter.next()) |entry| { 3283 switch (entry.value_ptr.focus.kind) { 3284 .custom => |custom| if (std.mem.eql(u8, custom, Quit.tab_kind)) { 3285 root_focus.setFocus(entry.key_ptr.*); 3286 // a Stack only builds its selected child, so the quit 3287 // button isn't in the focus tree until a build runs with 3288 // the quit tab selected. build once, then send a 3289 // synthetic arrow_down to drop focus from the tab onto 3290 // the button so it's ready to confirm. 3291 try self.root.build(allocator, .{ 3292 .min_size = .{ .width = null, .height = 40 }, 3293 .max_size = .{ .width = 80, .height = null }, 3294 }, root_focus); 3295 try self.root.input(allocator, .arrow_down, root_focus); 3296 break; 3297 }, 3298 else => {}, 3299 } 3300 } 3301 return false; 3302 } 3303 3304 // forward navigation: navigate() set next_page to the page to move to (a 3305 // cross-page link or tab change crossing pages) 3306 if (session.next_page) |route| { 3307 session.next_page = null; 3308 if (session.haxy_moment == null and session.local == null) return false; 3309 const previous_route = session.data.current_page; 3310 // the page we navigated to becomes the current page 3311 session.data.current_page = route; 3312 session.back = .available; 3313 3314 const arena = try allocator.create(std.heap.ArenaAllocator); 3315 arena.* = std.heap.ArenaAllocator.init(allocator); 3316 errdefer freeArena(allocator, arena); 3317 3318 const new_root = try initCurrentRoot(allocator, arena, session); 3319 3320 try self.history.append(allocator, .{ .root = self.root, .route = previous_route, .arena = self.arena, .user_id = self.user_id }); 3321 // drop the oldest entry (freeing its widget tree and arena) once over cap 3322 if (self.history.items.len > max_history) { 3323 var oldest = self.history.orderedRemove(0); 3324 oldest.root.deinit(allocator); 3325 freeArena(allocator, oldest.arena); 3326 } 3327 self.root = new_root; 3328 self.arena = arena; 3329 self.user_id = session.userId(); 3330 return true; 3331 } 3332 return false; 3333 } 3334 }; 3335 3336 pub fn initRoot(allocator: std.mem.Allocator, page: *const Page, session: *Session) !Widget { 3337 const page_widget: Widget = switch (page.*) { 3338 .home => |*p| .{ .home = try .init(allocator, p, session) }, 3339 .user => |*p| .{ .user = try .init(allocator, p, session) }, 3340 .repo => |*p| .{ .repo = try .init(allocator, p, session) }, 3341 .fork => |*p| .{ .fork = try .init(allocator, p, session) }, 3342 .not_found => .{ .not_found = try .init(allocator, session) }, 3343 }; 3344 3345 chooseAnsiArtForNavigation(session); 3346 3347 // on the TUI/SSH, the page sits above a one-row footer showing its web 3348 // url, when there's a web UI to point at 3349 var root = if (session.is_terminal) blk: { 3350 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 3351 errdefer box.deinit(allocator); 3352 const bg_id = bg_blk: { 3353 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 3354 errdefer background.deinit(allocator); 3355 const id = background.getFocus().id; 3356 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 3357 break :bg_blk id; 3358 }; 3359 if (session.web_url != null) { 3360 var footer = try widget.Footer.init(allocator, session); 3361 errdefer footer.deinit(allocator); 3362 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 3363 } 3364 box.getFocus().child_id = bg_id; 3365 break :blk Widget{ .box = box }; 3366 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 3367 errdefer root.deinit(allocator); 3368 3369 // input-owning views build their TextInputs in init, so reset their 3370 // registrations here 3371 session.text_inputs.clearRetainingCapacity(); 3372 3373 try root.build(allocator, .{ 3374 .min_size = .{ .width = null, .height = 40 }, 3375 .max_size = .{ .width = 100, .height = null }, 3376 }, root.getFocus()); 3377 3378 return root; 3379 } 3380 3381 // native and server-side sessions choose from the embedded collection. WASM 3382 // keeps the art serialized by the server instead. 3383 fn chooseAnsiArtForNavigation(session: *Session) void { 3384 if (comptime ansi_art.art.len == 0) return; 3385 if (session.data.current_page == .not_found) { 3386 session.data.ansi_art = ansi_art.not_found; 3387 return; 3388 } 3389 const io = session.io orelse return; 3390 var random: usize = undefined; 3391 io.random(std.mem.asBytes(&random)); 3392 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 3393 } 3394