╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
652 try text.writer.print("lines changed: {d}", .{stats.lines_added + stats.lines_changed}); 653 if (stats.lines_removed != 0) try text.writer.print("\nlines removed: {d}", .{stats.lines_removed}); 654 const bytes_added = stats.bytes_added >= stats.bytes_removed; 655 const bytes = if (bytes_added) stats.bytes_added - stats.bytes_removed else stats.bytes_removed - stats.bytes_added; 656 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 657 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 658 }); 659 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 660 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border = .single, .round_corners = true, .wrap_kind = .none, .top_label = .{ .text = " stats " } }); 661 errdefer tb.deinit(allocator); 662 tb.getFocus().mode = .all; 663 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 664 } 665 try self.addMessageBox(allocator, inner, commit, .preview); 666 } 667 668 // point the pane at its first row so focus recovery can land here. 669 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 670 671 // reset the scroll to the top for the newly-shown commit: directly on the 672 // terminal (the wasm offset), and via a version bump on the web (so the 673 // renderer's scroll id changes and JS drops the preserved position). 674 const sc = self.detailScroll(); 675 sc.x = 0; 676 sc.y = 0; 677 sc.getFocus().version +%= 1; 678 } 679 680 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 681 if (self.data.no_commits) return self.box.input(allocator, key, root_focus); 682 // scrolling crosses the sub header boundary the same way arrows do 683 const direction = inp.vertDirection(key); 684 if (self.headerActive()) { 685 // active means there is one 686 const header_view = self.header() orelse unreachable; 687 if (direction == .down) { 688 root_focus.setFocus(self.contentBox().getFocus().id); 689 return; 690 } 691 if (key == .enter) if (try header_view.submittedText(allocator)) |text| { 692 defer allocator.free(text); 693 return self.submit(text); 694 }; 695 return header_view.input(allocator, key, root_focus); 696 } 697 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 698 if (self.detailActive()) { 699 const inner = self.detailInner(); 700 if (inp.rowDelta(key, @intCast(inner.children.count()))) |delta| { 701 ui.widget.moveRowFocus(inner, self.detailScroll(), root_focus, delta); 702 } else if (key == .arrow_left) { 703 if (!ui.widget.moveInSelectedRow(inner, root_focus, false)) self.focusList(root_focus); 704 } else if (key == .arrow_right) { 705 _ = ui.widget.moveInSelectedRow(inner, root_focus, true); 706 } 707 } else { 708 try self.listInput(allocator, key, root_focus); 709 } 710 } 711 712 // navigate to the typed query's results, pinned to the list's ref. an 713 // empty query leaves the results for the plain log. 714 fn submit(self: *View, text: []const u8) !void { 715 if (text.len == 0 and self.data.search == null) return; 716 // an object view or a base-bounded list searches the default branch, so the url says so 717 const route = if (self.data.default_branch.len != 0) 718 self.data.handle.location.commitsRoute(.branch, self.data.default_branch, "") 719 else 720 self.data.handle.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, self.data.base_oid); 721 try self.session.navigate((route orelse return).withSearch(text) orelse return); 722 } 723 724 fn listInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 725 // up/down (and the scroll wheel) move the selection a row; page up/down 726 // jump a fixed amount. right/Enter cross into the detail pane. Enter/clicks 727 // on the "next" row become navigation in the host before reaching here. 728 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 729 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 730 return; 731 } 732 switch (key) { 733 .enter => if (self.selectedCommitIndex() != null) 734 self.focusDetail(root_focus) 735 else if (self.data.next_start) |next| { 736 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 737 }, 738 .arrow_right => self.focusDetail(root_focus), 739 // when the window is too narrow to lay out the detail pane beside 740 // the list, a click on a row opens it like enter. the row was just 741 // selected, so the detail is swapped to it ahead of the build. 742 .mouse => |mouse| if (self.contentBox().children.values()[detail_index].rect == null and ui.widget.clickOnSelectedRow(self.listBox(), root_focus, mouse)) { 743 try self.refreshDetail(allocator); 744 self.focusDetail(root_focus); 745 }, 746 else => {}, 747 } 748 } 749 750 // enter the detail pane. the host arrives here on right-arrow or Enter from the 751 // list. a pane with no rows can't be entered. setFocus handles the too-narrow 752 // case where the pane isn't laid out yet (it gets selected, then focused after 753 // the next build, landing on its remembered row). 754 fn focusDetail(self: *View, root_focus: *Focus) void { 755 if (self.detailInner().children.count() == 0) return; 756 root_focus.setFocus(self.detailOuter().getFocus().id); 757 } 758 759 // return to the list. 760 fn focusList(self: *View, root_focus: *Focus) void { 761 root_focus.setFocus(self.listScroll().getFocus().id); 762 } 763 764 pub fn clearGrid(self: *View) void { 765 self.box.clearGrid(); 766 } 767 768 pub fn getGrid(self: View) ?Grid { 769 return self.box.getGrid(); 770 } 771 772 pub fn getFocus(self: *View) *Focus { 773 return self.box.getFocus(); 774 } 775 776 fn contentAtTop(self: *View) bool { 777 if (self.detailActive()) { 778 const inner = self.detailInner(); 779 const cid = inner.getFocus().child_id orelse return true; 780 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 781 return first_focused and self.detailScroll().y == 0; 782 } 783 const lb = self.listBox(); 784 const cid = lb.getFocus().child_id orelse return true; 785 return lb.children.getIndex(cid) == 0; 786 } 787 788 // only the header's own row sits directly below the repository header. 789 pub fn atTop(self: *View) bool { 790 if (self.data.no_commits) return true; 791 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 792 return self.headerActive() or (!focusable and self.contentAtTop()); 793 } 794 795 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 796 const header_view = self.header() orelse return false; 797 return header_view.focusHeader(root_focus); 798 } 799 }; 800 801 // the "a:" navigation link for the commits page walking from commit `oid` within 802 // `data.handle.location`. 803 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 804 const route = data.handle.location.commitsRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 805 const url = try route.toUrl(page_arena); 806 return page_arena.allocator().print("a:{s}", .{url}); 807 } 808 809 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 810 // its query) and moves `from` along, so the search box survives paging. a fork 811 // or an object view roots the page at the commit itself. 812 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 813 if (data.handle.location != .repo or data.ref_or_oid == .object) { 814 return data.handle.location.commitsRoute(.object, oid, data.base_oid); 815 } 816 const route = data.handle.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, data.base_oid) orelse return null; 817 const paged = route.withFrom(oid) orelse return null; 818 return paged.withSearch(data.search orelse return paged); 819 } 820 821 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 822 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 823 const url = try route.toUrl(page_arena); 824 return page_arena.allocator().print("a:{s}", .{url}); 825 } 826 827 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 828 // directory, within `location`. 829 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 830 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 831 const url = try route.toUrl(page_arena); 832 return page_arena.allocator().print("a:{s}", .{url}); 833 } 834 835 // the in-page "ai:" anchor for selecting a commit, showing its whole message 836 // when `message` is set. the href is only followed with js off. 837 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, message: bool) ![]const u8 { 838 // a result roots the same results page at its commit, so the query 839 // survives following the row 840 if (data.search != null) { 841 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 842 return page_arena.allocator().print("ai:{s}", .{try route.toUrl(page_arena)}); 843 } 844 const route = (if (message) 845 data.handle.location.commitMessageRoute(.object, commit.oid, data.base_oid) 846 else 847 data.handle.location.commitsRoute(.object, commit.oid, data.base_oid)) orelse return error.RouteTooLong; 848 const url = try route.toUrl(page_arena); 849 return page_arena.allocator().print("ai:{s}", .{url}); 850 } 851 852 // the "a:" link to the page showing `oid`'s message on its own. 853 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 854 const route = data.handle.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 855 const url = try route.toUrl(page_arena); 856 return page_arena.allocator().print("a:{s}", .{url}); 857 } 858