╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
726 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 727 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 728 }); 729 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 730 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .label = " stats " }); 731 errdefer tb.deinit(allocator); 732 tb.getFocus().mode = .all; 733 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 734 } 735 try addLink(allocator, inner, "view files at this commit", try filesObjectLink(self.session.page_arena, self.data.location, commit.oid)); 736 } 737 738 try (Diff{ 739 .route = .{ .commit = .{ .location = self.data.location, .oid = commit.oid, .base_oid = self.data.base_oid } }, 740 .path = d.path, 741 .window = commit.window, 742 }).appendWindow(allocator, self.session, inner); 743 }, 744 } 745 746 // point the pane at its first row so focus recovery can land here. 747 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 748 749 // reset the scroll to the top for the newly-shown commit: directly on the 750 // terminal (the wasm offset), and via a version bump on the web (so the 751 // renderer's scroll id changes and JS drops the preserved position). 752 const sc = self.diffScroll(); 753 sc.x = 0; 754 sc.y = 0; 755 sc.getFocus().version +%= 1; 756 } 757 758 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 759 // scrolling crosses the sub header boundary the same way arrows do 760 const direction = inp.vertDirection(key); 761 if (self.headerActive()) { 762 // active means there is one 763 const header_view = self.header() orelse unreachable; 764 if (direction == .down) { 765 root_focus.setFocus(self.contentBox().getFocus().id); 766 return; 767 } 768 if (key == .enter) if (try header_view.submittedText(allocator)) |text| { 769 defer allocator.free(text); 770 return self.submit(text); 771 }; 772 return header_view.input(allocator, key, root_focus); 773 } 774 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 775 if (self.diffActive()) { 776 const diff_view = &self.diffOuter().children.values()[0].widget.diff_view; 777 if (key == .arrow_left and self.diffScroll().x == 0) { 778 if (!diff_view.moveInRow(root_focus, false)) self.focusList(root_focus); 779 } else { 780 try diff_view.input(allocator, key, root_focus); 781 } 782 } else { 783 try self.listInput(key, root_focus); 784 } 785 } 786 787 // navigate to the typed query's results, pinned to the list's ref. an 788 // empty query leaves the results for the plain log. 789 fn submit(self: *View, text: []const u8) !void { 790 if (text.len == 0 and self.data.search == null) return; 791 const route = self.data.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, 0, "", self.data.base_oid) orelse return; 792 try self.session.navigate(route.withSearch(text) orelse return); 793 } 794 795 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 796 // up/down (and the scroll wheel) move the selection a row; page up/down 797 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 798 // on the "next" row become navigation in the host before reaching here. 799 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 800 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 801 return; 802 } 803 switch (key) { 804 .enter => if (self.selectedCommitIndex() != null) 805 self.focusDiff(root_focus) 806 else if (self.data.next_start) |next| { 807 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 808 }, 809 .arrow_right => self.focusDiff(root_focus), 810 else => {}, 811 } 812 } 813 814 // enter the diff pane. the host arrives here on right-arrow or Enter from the 815 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 816 // case where the pane isn't laid out yet (it gets selected, then focused after 817 // the next build, landing on its remembered hunk). 818 fn focusDiff(self: *View, root_focus: *Focus) void { 819 if (self.diffInner().children.count() == 0) return; 820 root_focus.setFocus(self.diffOuter().getFocus().id); 821 } 822 823 // return to the list. 824 fn focusList(self: *View, root_focus: *Focus) void { 825 root_focus.setFocus(self.listScroll().getFocus().id); 826 } 827 828 pub fn clearGrid(self: *View) void { 829 self.box.clearGrid(); 830 } 831 832 pub fn getGrid(self: View) ?Grid { 833 return self.box.getGrid(); 834 } 835 836 pub fn getFocus(self: *View) *Focus { 837 return self.box.getFocus(); 838 } 839 840 fn contentAtTop(self: *View) bool { 841 if (self.diffActive()) { 842 const inner = self.diffInner(); 843 const cid = inner.getFocus().child_id orelse return true; 844 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 845 return first_focused and self.diffScroll().y == 0; 846 } 847 const lb = self.listBox(); 848 const cid = lb.getFocus().child_id orelse return true; 849 return lb.children.getIndex(cid) == 0; 850 } 851 852 // only the header's own row sits directly below the repository header. 853 pub fn atTop(self: *View) bool { 854 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 855 return self.headerActive() or (!focusable and self.contentAtTop()); 856 } 857 858 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 859 const header_view = self.header() orelse return false; 860 return header_view.focusHeader(root_focus); 861 } 862 }; 863 864 // the "a:" navigation link for the commits page walking from commit `oid` within 865 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 866 // to `path` ("" = every file). 867 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 868 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 869 const url = try route.toUrl(page_arena); 870 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 871 } 872 873 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 874 // its query) and moves `from` along, so the search box survives paging. a fork 875 // or an object view roots the page at the commit itself. 876 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 877 if (data.location != .repo or data.ref_or_oid == .object) { 878 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 879 } 880 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 881 const paged = route.withFrom(oid) orelse return null; 882 return paged.withSearch(data.search orelse return paged); 883 } 884 885 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 886 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 887 const url = try route.toUrl(page_arena); 888 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 889 } 890 891 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 892 // directory, within `location`. 893 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 894 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 895 const url = try route.toUrl(page_arena); 896 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 897 } 898 899 // the in-page "ai:" anchor for selecting a commit with its current pane content 900 // and window. the href is only followed with js off. 901 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 902 // a result roots the same results page at its commit, so the query 903 // survives following the row 904 if (data.search != null) { 905 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 906 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 907 } 908 const route = (switch (content) { 909 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 910 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 911 }) orelse return error.RouteTooLong; 912 const url = try route.toUrl(page_arena); 913 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 914 } 915 916 // the "a:" link to the page showing `oid`'s message on its own. 917 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 918 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 919 const url = try route.toUrl(page_arena); 920 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 921 } 922