╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repos.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
55 errdefer list.deinit(allocator); 56 57 break :blk View{ 58 .list = list, 59 .data = data, 60 }; 61 }; 62 errdefer self.deinit(allocator); 63 64 var arena = std.heap.ArenaAllocator.init(allocator); 65 defer arena.deinit(); 66 const aa = arena.allocator(); 67 68 const lines = try aa.alloc([]const u8, data.repos.len); 69 const links = try aa.alloc([]const u8, data.repos.len); 70 for (data.repos, 0..) |repo, i| { 71 lines[i] = try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo.name, repo.description }); 72 // clicking a repo opens its page; the "a:" prefix makes the web 73 // renderer emit an <a href="/repo/alice/foo"> anchor. skip the link 74 // when the owner is unknown so it isn't a dead route. 75 const owner = data.owner_names[i]; 76 links[i] = if (owner.len > 0) try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}", .{ owner, repo.name }) else ""; 77 } 78 try self.list.setItems(allocator, lines, links); 79 80 return self; 81 } 82 83 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 84 self.list.deinit(allocator); 85 } 86 87 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 88 try self.list.build(allocator, constraint, root_focus); 89 } 90 91 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 92 try self.list.input(allocator, key, root_focus); 93 } 94 95 pub fn clearGrid(self: *View) void { 96 self.list.clearGrid(); 97 } 98 99 pub fn getGrid(self: View) ?Grid { 100 return self.list.getGrid(); 101 } 102 103 pub fn getFocus(self: *View) *Focus { 104 return self.list.getFocus(); 105 } 106 107 pub fn getSelectedIndex(self: View) ?usize { 108 return self.list.getSelectedIndex(); 109 } 110 }; 111