╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
642 }, 643 .arrow_right => self.focusDiff(root_focus), 644 else => {}, 645 } 646 } 647 648 // enter the diff pane. the host arrives here on right-arrow or Enter from the 649 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 650 // case where the pane isn't laid out yet (it gets selected, then focused after 651 // the next build, landing on its remembered hunk). 652 fn focusDiff(self: *View, root_focus: *Focus) void { 653 if (self.diffInner().children.count() == 0) return; 654 root_focus.setFocus(self.diffOuter().getFocus().id); 655 } 656 657 // return to the list. 658 fn focusList(self: *View, root_focus: *Focus) void { 659 root_focus.setFocus(self.listScroll().getFocus().id); 660 } 661 662 pub fn clearGrid(self: *View) void { 663 self.box.clearGrid(); 664 } 665 666 pub fn getGrid(self: View) ?Grid { 667 return self.box.getGrid(); 668 } 669 670 pub fn getFocus(self: *View) *Focus { 671 return self.box.getFocus(); 672 } 673 674 fn contentAtTop(self: *View) bool { 675 if (self.diffActive()) { 676 const inner = self.diffInner(); 677 const cid = inner.getFocus().child_id orelse return true; 678 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 679 return first_focused and self.diffScroll().y == 0; 680 } 681 const lb = self.listBox(); 682 const cid = lb.getFocus().child_id orelse return true; 683 return lb.children.getIndex(cid) == 0; 684 } 685 686 // only the clone-url row sits directly below the repository header. 687 pub fn atTop(self: *View) bool { 688 return self.headerActive() or (!self.header().hasCloneUrl() and self.contentAtTop()); 689 } 690 691 pub fn focusCloneUrl(self: *View, root_focus: *Focus) bool { 692 return self.header().focusCloneUrl(root_focus); 693 } 694 }; 695 696 // the "a:" navigation link for the commits page walking from commit `oid` within 697 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 698 // to `path` ("" = every file). 699 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 700 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 701 const url = try route.toUrl(page_arena); 702 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 703 } 704 705 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 706 // directory, within `location`. 707 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 708 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 709 const url = try route.toUrl(page_arena); 710 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 711 } 712 713 // the in-page "ai:" anchor for selecting a commit with its current pane content 714 // and window. the href is only followed with js off. 715 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 716 const route = (switch (content) { 717 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 718 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 719 }) orelse return error.RouteTooLong; 720 const url = try route.toUrl(page_arena); 721 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 722 } 723 724 // the "a:" link to the page showing `oid`'s message on its own. 725 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 726 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 727 const url = try route.toUrl(page_arena); 728 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 729 } 730 731 // the clone url shown above the log. 732 pub const Header = struct { 733 pub const View = struct { 734 box: wgt.Box(ui.Widget), 735 736 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, location: ui.RoutablePage.RepoLocation) !Header.View { 737 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 738 errdefer box.deinit(allocator); 739 740 // the spacer pushes the clone url to the right edge. 741 { 742 var spacer = try ui.widget.Spacer.init(allocator); 743 errdefer spacer.deinit(allocator); 744 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 745 } 746 747 if (session.data.host_kind == .server) { 748 if (try ui.widget.CopyableText.initClone(allocator, session, location)) |value| { 749 var clone_url = value; 750 errdefer clone_url.deinit(allocator); 751 const min_width = clone_url.minWidth(); 752 box.getFocus().child_id = clone_url.getFocus().id; 753 try box.children.put(allocator, clone_url.getFocus().id, .{ .widget = .{ .copyable_text = clone_url }, .rect = null, .min_size = .{ .width = min_width, .height = 3 }, .max_size = .{ .width = min_width, .height = 3 } }); 754 } 755 } 756 757 return .{ .box = box }; 758 } 759 760 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 761 self.box.deinit(allocator); 762 } 763 764 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 765 self.clearGrid(); 766 try self.box.build(allocator, constraint, root_focus); 767 } 768 769 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 770 const clone_url = self.cloneUrl() orelse return; 771 try clone_url.input(allocator, key, root_focus); 772 } 773 774 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 775 const clone_url = self.cloneUrl() orelse return false; 776 root_focus.setFocus(clone_url.getFocus().id); 777 return true; 778 } 779 780 pub fn hasCloneUrl(self: *Header.View) bool { 781 return self.cloneUrl() != null; 782 } 783 784 fn cloneUrl(self: *Header.View) ?*ui.widget.CopyableText { 785 for (self.box.children.values()) |*child| switch (child.widget) { 786 .copyable_text => |*copyable_text| return copyable_text, 787 else => {}, 788 }; 789 return null; 790 } 791 792 pub fn clearGrid(self: *Header.View) void { 793 self.box.clearGrid(); 794 } 795 796 pub fn getGrid(self: Header.View) ?Grid { 797 return self.box.getGrid(); 798 } 799 800 pub fn getFocus(self: *Header.View) *Focus { 801 return self.box.getFocus(); 802 } 803 }; 804 }; 805