╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Users.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
66 67 pub fn init(allocator: std.mem.Allocator, data: *const Self, web_native: bool) !View { 68 var self = blk: { 69 var list = try ui.FlowBox.Scroll.init(allocator, .{ .cell_height = 1 }, web_native); 70 errdefer list.deinit(allocator); 71 72 break :blk View{ 73 .list = list, 74 .data = data, 75 }; 76 }; 77 errdefer self.deinit(allocator); 78 79 var arena = std.heap.ArenaAllocator.init(allocator); 80 defer arena.deinit(); 81 const aa = arena.allocator(); 82 83 // a leading "previous" row off the first window, one row per user, then 84 // a trailing "next" row when more remain. each window row navigates to the 85 // adjacent window (full reload on web, Nav rebuild on the TUI). 86 var items: std.ArrayList(ui.FlowBox.Item) = .empty; 87 if (data.after > 0) 88 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:/users?after={d}", .{data.after -| page_size}) }); 89 for (data.users) |user| 90 // clicking a user opens their page; the "a:" prefix makes the web 91 // renderer emit an <a href="/user/foo"> anchor. 92 try items.append(aa, .{ 93 .text = try std.fmt.allocPrint(aa, "{s} ({s})", .{ user.name, user.display_name }), 94 .link = try std.fmt.allocPrint(aa, "a:/user/{s}", .{user.name}), 95 }); 96 if (data.next_after) |next_after| 97 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/users?after={d}", .{next_after}) }); 98 try self.list.setItems(allocator, items.items); 99 100 return self; 101 } 102 103 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 104 self.list.deinit(allocator); 105 } 106 107 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 108 try self.list.build(allocator, constraint, root_focus); 109 } 110 111 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 112 try self.list.input(allocator, key, root_focus); 113 } 114 115 pub fn clearGrid(self: *View) void { 116 self.list.clearGrid(); 117 } 118 119 pub fn getGrid(self: View) ?Grid { 120 return self.list.getGrid(); 121 } 122 123 pub fn getFocus(self: *View) *Focus { 124 return self.list.getFocus(); 125 } 126 127 pub fn getSelectedIndex(self: View) ?usize { 128 return self.list.getSelectedIndex(); 129 } 130 }; 131