╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
511 } else if (session.data.host_kind == .server) { 512 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 513 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 514 errdefer new_user_view.deinit(allocator); 515 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 516 } 517 518 if (session.data.host_kind == .server) { 519 var user_view = try ui.UserSettings.initView(allocator, session); 520 errdefer user_view.deinit(allocator); 521 try stack.children.put(allocator, user_view.getFocus().id, user_view); 522 } 523 524 if (session.is_terminal) { 525 var quit_view = try Quit.View.init(allocator, session); 526 errdefer quit_view.deinit(allocator); 527 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 528 } 529 530 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 531 } 532 533 var self = View{ .box = box }; 534 // a page opens on its tabs, except that search results open in the 535 // tab's own search box. 536 const results = data.files.find != null or 537 (data.changes == .commits and data.changes.commits.search != null) or 538 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 539 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 540 return self; 541 } 542 543 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 544 self.box.deinit(allocator); 545 } 546 547 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 548 self.clearGrid(); 549 const header = &self.box.children.values()[header_index].widget.repo_header; 550 const stack = &self.box.children.values()[stack_index].widget.stack; 551 552 // each header tab maps 1:1 to a stack child by position 553 if (header.getSelectedIndex()) |index| 554 stack.getFocus().child_id = stack.children.keys()[index]; 555 try self.box.build(allocator, constraint, root_focus); 556 } 557 558 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 559 const stack = &self.box.children.values()[stack_index].widget.stack; 560 if (self.getFocus().child_id) |child_id| { 561 if (self.box.children.getIndex(child_id)) |current_index| { 562 const child = &self.box.children.values()[current_index].widget; 563 var index = current_index; 564 565 const direction = inp.vertDirection(key); 566 567 switch (direction) { 568 .up => { 569 switch (child.*) { 570 .repo_header => { 571 try child.input(allocator, key, root_focus); 572 }, 573 .stack => { 574 if (child.stack.getSelected()) |selected_widget| { 575 if (selected_widget.atTop(root_focus)) { 576 index = header_index; 577 } else { 578 try child.input(allocator, key, root_focus); 579 } 580 } 581 }, 582 else => {}, 583 } 584 }, 585 .down => { 586 switch (child.*) { 587 .repo_header => { 588 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 589 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 590 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 591 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 592 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 593 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 594 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 595 else => {}, 596 }; 597 index = stack_index; 598 }, 599 .stack => { 600 try child.input(allocator, key, root_focus); 601 }, 602 else => {}, 603 } 604 }, 605 .none => { 606 try child.input(allocator, key, root_focus); 607 }, 608 } 609 610 if (index != current_index) { 611 root_focus.setFocus(self.box.children.keys()[index]); 612 } 613 } 614 } 615 } 616 617 pub fn clearGrid(self: *View) void { 618 self.box.clearGrid(); 619 } 620 621 pub fn getGrid(self: View) ?Grid { 622 return self.box.getGrid(); 623 } 624 625 pub fn getFocus(self: *View) *Focus { 626 return self.box.getFocus(); 627 } 628 }; 629