╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repos.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
65 return .{ 66 .repos = repos.items, 67 .owner_names = owner_names.items, 68 .start = start, 69 .next_start = if (end < count) end else null, 70 }; 71 } 72 73 pub const View = struct { 74 list: ui.FlowBox.Scroll, 75 data: *const Self, 76 77 pub fn init(allocator: std.mem.Allocator, data: *const Self, web_native: bool) !View { 78 var self = blk: { 79 var list = try ui.FlowBox.Scroll.init(allocator, .{}, web_native); 80 errdefer list.deinit(allocator); 81 82 break :blk View{ 83 .list = list, 84 .data = data, 85 }; 86 }; 87 errdefer self.deinit(allocator); 88 89 var arena = std.heap.ArenaAllocator.init(allocator); 90 defer arena.deinit(); 91 const aa = arena.allocator(); 92 93 // a leading "previous" row off the first window, one row per repo, then 94 // a trailing "next" row when more remain. each window row navigates to the 95 // adjacent window (full reload on web, Nav rebuild on the TUI). 96 var items: std.ArrayList(ui.FlowBox.Item) = .empty; 97 if (data.start > 0) 98 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:/repos/start:{d}", .{data.start -| page_size}) }); 99 for (data.repos, 0..) |repo, i| { 100 // clicking a repo opens its page; the "a:" prefix makes the web 101 // renderer emit an <a href="/repo/alice/foo"> anchor. skip the link 102 // when the owner is unknown so it isn't a dead route. 103 const owner = data.owner_names[i]; 104 try items.append(aa, .{ 105 .text = try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo.event.name, repo.event.description }), 106 .link = if (owner.len > 0) try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}", .{ owner, repo.event.name }) else "", 107 }); 108 } 109 if (data.next_start) |next_start| 110 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/repos/start:{d}", .{next_start}) }); 111 try self.list.setItems(allocator, items.items); 112 113 return self; 114 } 115 116 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 117 self.list.deinit(allocator); 118 } 119 120 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 121 try self.list.build(allocator, constraint, root_focus); 122 } 123 124 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 125 try self.list.input(allocator, key, root_focus); 126 } 127 128 pub fn clearGrid(self: *View) void { 129 self.list.clearGrid(); 130 } 131 132 pub fn getGrid(self: View) ?Grid { 133 return self.list.getGrid(); 134 } 135 136 pub fn getFocus(self: *View) *Focus { 137 return self.list.getFocus(); 138 } 139 140 pub fn getSelectedIndex(self: View) ?usize { 141 return self.list.getSelectedIndex(); 142 } 143 }; 144