╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3061 3062 chooseAnsiArtForNavigation(session); 3063 3064 // on the TUI/SSH, the page sits above a one-row footer showing its web 3065 // url, when there's a web UI to point at 3066 var root = if (session.is_terminal) blk: { 3067 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 3068 errdefer box.deinit(allocator); 3069 const bg_id = bg_blk: { 3070 var background = try widget.AnsiBackground.init(allocator, page_widget, session); 3071 errdefer background.deinit(allocator); 3072 const id = background.getFocus().id; 3073 try box.children.put(allocator, id, .{ .widget = .{ .background = background }, .rect = null, .min_size = null }); 3074 break :bg_blk id; 3075 }; 3076 if (session.web_port != null) { 3077 var footer = try widget.Footer.init(allocator, session); 3078 errdefer footer.deinit(allocator); 3079 try box.children.put(allocator, footer.getFocus().id, .{ .widget = .{ .footer = footer }, .rect = null, .min_size = .{ .width = null, .height = 1 } }); 3080 } 3081 box.getFocus().child_id = bg_id; 3082 break :blk Widget{ .box = box }; 3083 } else Widget{ .background = try widget.AnsiBackground.init(allocator, page_widget, session) }; 3084 errdefer root.deinit(allocator); 3085 3086 // input-owning views build their TextInputs in init, so reset their 3087 // registrations here 3088 session.text_inputs.clearRetainingCapacity(); 3089 3090 try root.build(allocator, .{ 3091 .min_size = .{ .width = null, .height = 40 }, 3092 .max_size = .{ .width = 100, .height = null }, 3093 }, root.getFocus()); 3094 3095 return root; 3096 } 3097 3098 // native and server-side sessions choose from the embedded collection. WASM 3099 // keeps the art serialized by the server instead. 3100 fn chooseAnsiArtForNavigation(session: *Session) void { 3101 if (comptime ansi_art.art.len == 0) return; 3102 if (session.data.current_page == .not_found) { 3103 session.data.ansi_art = ansi_art.not_found; 3104 return; 3105 } 3106 const io = session.io orelse return; 3107 var random: usize = undefined; 3108 io.random(std.mem.asBytes(&random)); 3109 session.data.ansi_art = ansi_art.art[random % ansi_art.art.len]; 3110 } 3111