╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
406 .commits => |*commits| { 407 var commits_view = try Commits.View.init(allocator, commits, session); 408 errdefer commits_view.deinit(allocator); 409 try stack.children.put(allocator, commits_view.getFocus().id, .{ .repo_commits = commits_view }); 410 }, 411 } 412 413 // refs — the repo's branches and tags. 414 { 415 var refs_view = try Refs.View.init(allocator, &data.refs, session); 416 errdefer refs_view.deinit(allocator); 417 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 418 } 419 420 // issues — the repo's issue tracker and comment permalinks. 421 { 422 var issues_view = try Issues.View.init(allocator, &data.issues, session); 423 errdefer issues_view.deinit(allocator); 424 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 425 } 426 427 // patches and their comment permalinks. 428 { 429 var patches_view = try Patches.View.init(allocator, &data.patches, session); 430 errdefer patches_view.deinit(allocator); 431 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 432 } 433 434 // discussions and their comment permalinks. 435 { 436 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 437 errdefer discussions_view.deinit(allocator); 438 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 439 } 440 441 if (data.handle.canWrite()) { 442 var events_view = try Events.View.init(allocator, &data.events, session); 443 errdefer events_view.deinit(allocator); 444 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 445 } 446 447 if (data.undo) |*undo| { 448 var undo_view = try Undo.View.init(allocator, undo, session); 449 errdefer undo_view.deinit(allocator); 450 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 451 } 452 453 // the header only shows the new repo tab with a login 454 // and the auth tab outside local mode, so keep the stack's children 1:1 with 455 // the tabs by skipping the same views. 456 if (session.data.user_id != null) { 457 const identity = try std.fmt.allocPrint(session.page_arena.allocator(), "{s}/{s}", .{ data.header.owner_name, data.header.name }); 458 const route = ui.RoutablePage{ .repo_new_repo = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 459 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 460 errdefer new_repo_view.deinit(allocator); 461 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 462 } 463 464 if (session.data.host_kind == .server) { 465 var auth_view = try Auth.View.init(allocator, &data.auth, session); 466 errdefer auth_view.deinit(allocator); 467 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 468 } 469 470 if (session.is_terminal) { 471 var quit_view = try Quit.View.init(allocator, session); 472 errdefer quit_view.deinit(allocator); 473 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 474 } 475 476 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 477 } 478 479 var self = View{ .box = box }; 480 // a page opens on its tabs, except that search results open in the 481 // tab's own search box. 482 const results = data.files.find != null or 483 (data.changes == .commits and data.changes.commits.search != null) or 484 data.issues.search != null or data.patches.search != null or data.discussions.search != null; 485 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 486 return self; 487 } 488 489 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 490 self.box.deinit(allocator); 491 } 492 493 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 494 self.clearGrid(); 495 const header = &self.box.children.values()[header_index].widget.repo_header; 496 const stack = &self.box.children.values()[stack_index].widget.stack; 497 498 // each header tab maps 1:1 to a stack child by position 499 if (header.getSelectedIndex()) |index| 500 stack.getFocus().child_id = stack.children.keys()[index]; 501 try self.box.build(allocator, constraint, root_focus); 502 } 503 504 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 505 const stack = &self.box.children.values()[stack_index].widget.stack; 506 if (self.getFocus().child_id) |child_id| { 507 if (self.box.children.getIndex(child_id)) |current_index| { 508 const child = &self.box.children.values()[current_index].widget; 509 var index = current_index; 510 511 const direction = inp.vertDirection(key); 512 513 switch (direction) { 514 .up => { 515 switch (child.*) { 516 .repo_header => { 517 try child.input(allocator, key, root_focus); 518 }, 519 .stack => { 520 if (child.stack.getSelected()) |selected_widget| { 521 if (selected_widget.atTop(root_focus)) { 522 index = header_index; 523 } else { 524 try child.input(allocator, key, root_focus); 525 } 526 } 527 }, 528 else => {}, 529 } 530 }, 531 .down => { 532 switch (child.*) { 533 .repo_header => { 534 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 535 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 536 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 537 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 538 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 539 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 540 else => {}, 541 }; 542 index = stack_index; 543 }, 544 .stack => { 545 try child.input(allocator, key, root_focus); 546 }, 547 else => {}, 548 } 549 }, 550 .none => { 551 try child.input(allocator, key, root_focus); 552 }, 553 } 554 555 if (index != current_index) { 556 root_focus.setFocus(self.box.children.keys()[index]); 557 } 558 } 559 } 560 } 561 562 pub fn clearGrid(self: *View) void { 563 self.box.clearGrid(); 564 } 565 566 pub fn getGrid(self: View) ?Grid { 567 return self.box.getGrid(); 568 } 569 570 pub fn getFocus(self: *View) *Focus { 571 return self.box.getFocus(); 572 } 573 }; 574