╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
247 self.box.deinit(allocator); 248 } 249 250 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 251 self.clearGrid(); 252 const header = &self.box.children.values()[header_index].widget.repo_header; 253 const stack = &self.box.children.values()[stack_index].widget.stack; 254 255 // each header tab maps 1:1 to a stack child by position. mirror the 256 // selection into current_page so the host can push the matching url; 257 // all repo tabs share the .repo parent, so this stays on the page 258 // rather than navigating. 259 if (header.getSelectedIndex()) |index| { 260 stack.getFocus().child_id = stack.children.keys()[index]; 261 switch (std.meta.activeTag(stack.children.values()[index])) { 262 // files/commits carry this page's content route (directory / log 263 // page); settings/auth carry only "owner/name". 264 .repo_commits => self.session.data.current_page = .{ .repo_commits = .{ .name = self.data.commits_route_name, .after = self.data.commits_after } }, 265 // the refs tab mirrors this page's paginated column + offset. 266 .repo_refs => self.session.data.current_page = .{ .repo_refs = .{ .name = self.data.identity, .kind = self.data.refs.kind, .after = self.data.refs.after } }, 267 // the issues tab mirrors this page's tag filter (issue urls 268 // themselves never carry the tag). 269 .repo_issues => self.session.data.current_page = ui.RoutablePage.repoIssuesRoute(self.data.identity.slice(), self.data.issues.tag, "") orelse self.session.data.current_page, 270 .home_settings => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 271 .home_auth => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 272 // the quit tab is tty-only and not a route, so leave current_page 273 // alone (nothing to mirror into the url). 274 .quit => {}, 275 // the files tab (this page's directory route) 276 else => self.session.data.current_page = .{ .repo_files = .{ .name = self.data.route_name, .after = self.data.files_after } }, 277 } 278 } 279 try self.box.build(allocator, constraint, root_focus); 280 } 281 282 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 283 if (self.getFocus().child_id) |child_id| { 284 if (self.box.children.getIndex(child_id)) |current_index| { 285 const child = &self.box.children.values()[current_index].widget; 286 var index = current_index; 287 288 const direction = inp.vertDirection(key); 289 290 switch (direction) { 291 .up => { 292 switch (child.*) { 293 .repo_header => { 294 try child.input(allocator, key, root_focus); 295 }, 296 .stack => { 297 if (child.stack.getSelected()) |selected_widget| { 298 const at_top = switch (selected_widget.*) { 299 .repo_files => |*v| v.getSelectedIndex() == 0, 300 .repo_commits => |*v| v.getSelectedIndex() == 0, 301 .repo_refs => |*v| v.getSelectedIndex() == 0, 302 .repo_issues => |*v| v.getSelectedIndex() == 0, 303 .home_settings => |*v| v.getSelectedIndex() == 0, 304 .home_auth => |*v| v.getSelectedIndex() == 0, 305 .quit => |*v| v.getSelectedIndex() == 0, 306 else => false, 307 }; 308 if (at_top) { 309 index = header_index; 310 } else { 311 try child.input(allocator, key, root_focus); 312 } 313 } 314 }, 315 else => {}, 316 } 317 }, 318 .down => { 319 switch (child.*) { 320 .repo_header => { 321 index = stack_index; 322 }, 323 .stack => { 324 try child.input(allocator, key, root_focus); 325 }, 326 else => {}, 327 } 328 }, 329 .none => { 330 try child.input(allocator, key, root_focus); 331 }, 332 } 333 334 if (index != current_index) { 335 root_focus.setFocus(self.box.children.keys()[index]); 336 } 337 } 338 } 339 } 340 341 pub fn clearGrid(self: *View) void { 342 self.box.clearGrid(); 343 } 344 345 pub fn getGrid(self: View) ?Grid { 346 return self.box.getGrid(); 347 } 348 349 pub fn getFocus(self: *View) *Focus { 350 return self.box.getFocus(); 351 } 352 }; 353