╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ UsersAndRepos.zig ────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
174 pub fn input(self: *View, key: inp.Key, root_focus: *Focus) !void { 175 if (self.getFocus().child_id) |child_id| { 176 if (self.box.children.getIndex(child_id)) |current_index| { 177 const child = &self.box.children.values()[current_index].widget; 178 179 const index = blk: { 180 switch (key) { 181 .arrow_left => { 182 if (current_index == repo_list_index) { 183 break :blk user_list_index; 184 } 185 }, 186 .arrow_right => { 187 if (current_index == user_list_index) { 188 break :blk repo_list_index; 189 } 190 }, 191 .codepoint => { 192 switch (key.codepoint) { 193 13 => { 194 if (current_index == user_list_index) { 195 break :blk repo_list_index; 196 } 197 }, 198 127, '\x1B' => { 199 if (current_index == repo_list_index) { 200 break :blk user_list_index; 201 } 202 }, 203 else => {}, 204 } 205 }, 206 else => {}, 207 } 208 try child.input(key, root_focus); 209 break :blk current_index; 210 }; 211 212 if (index != current_index) { 213 try root_focus.setFocus(self.box.children.keys()[index]); 214 } 215 } 216 } 217 } 218 219 pub fn clearGrid(self: *View) void { 220 self.box.clearGrid(); 221 } 222 223 pub fn getGrid(self: View) ?Grid { 224 return self.box.getGrid(); 225 } 226 227 pub fn getFocus(self: *View) *Focus { 228 return self.box.getFocus(); 229 } 230 231 fn updateRepos(self: *View) !void { 232 const user_list = &self.box.children.values()[user_list_index].widget.selectable_list; 233 const repo_list = &self.box.children.values()[repo_list_index].widget.selectable_list; 234 235 const user_index = user_list.getSelectedIndex(); 236 if (user_index == self.last_user_index) return; 237 self.last_user_index = user_index; 238 239 const repos = if (user_index) |i| self.data.users[i].repos else &.{}; 240 241 var arena = std.heap.ArenaAllocator.init(self.allocator); 242 defer arena.deinit(); 243 const aa = arena.allocator(); 244 245 const repo_lines = try aa.alloc([]const u8, repos.len); 246 for (repos, 0..) |repo_event, i| { 247 repo_lines[i] = try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo_event.name, repo_event.description }); 248 } 249 try repo_list.setItems(repo_lines); 250 } 251 }; 252