╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
777 fn focusDiff(self: *View, root_focus: *Focus) !void { 778 if (self.diffInner().children.count() == 0) return; 779 root_focus.setFocus(self.diffOuter().getFocus().id); 780 } 781 782 // return to the list. 783 fn focusList(self: *View, root_focus: *Focus) !void { 784 root_focus.setFocus(self.listScroll().getFocus().id); 785 } 786 787 pub fn clearGrid(self: *View) void { 788 self.box.clearGrid(); 789 } 790 791 pub fn getGrid(self: View) ?Grid { 792 return self.box.getGrid(); 793 } 794 795 pub fn getFocus(self: *View) *Focus { 796 return self.box.getFocus(); 797 } 798 799 // for the parent's "scroll up at the top jumps to the header" check. in the 800 // diff pane that means the first hunk is focused and the diff can't scroll up 801 // any further; otherwise up-arrow stays in the pane (scrolling or moving 802 // between hunks). when the list holds focus, report its selection directly. 803 pub fn getSelectedIndex(self: *View) ?usize { 804 if (self.diffActive()) { 805 const inner = self.diffInner(); 806 const cid = inner.getFocus().child_id orelse return 1; 807 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 808 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 809 } 810 const lb = self.listBox(); 811 const cid = lb.getFocus().child_id orelse return null; 812 return lb.children.getIndex(cid); 813 } 814 }; 815 816 // the "a:" navigation link for the commits page walking from commit `oid` within 817 // `identity`, windowing the selected commit's diff from hunk `start`, filtered 818 // to `path` ("" = every file). 819 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 820 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, start, path) orelse return error.RouteTooLong; 821 const url = try route.toUrl(page_arena); 822 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 823 } 824 825 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 826 // directory, within `identity` ("owner/name"). 827 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 828 const route = ui.RoutablePage.repoFilesRoute(identity, .object, oid, "", 0) orelse return error.RouteTooLong; 829 const url = try route.toUrl(page_arena); 830 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 831 } 832 833 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 834 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 835 // in-page (crossPageLink ignores it); the href is only followed with js off. 836 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, path: []const u8) ![]const u8 { 837 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, 0, path) orelse return error.RouteTooLong; 838 const url = try route.toUrl(page_arena); 839 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 840 } 841 842 // the "viewing <ref_or_oid> <value>" banner shown above the log. 843 pub const Header = struct { 844 content: []const u8, 845 846 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 847 return .{ 848 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), value }), 849 }; 850 } 851 852 pub const View = struct { 853 box: wgt.Box(ui.Widget), 854 data: *const Header, 855 856 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 857 _ = session; 858 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 859 errdefer box.deinit(allocator); 860 861 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 862 errdefer text_box.deinit(allocator); 863 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null }); 864 865 return .{ .box = box, .data = data }; 866 } 867 868 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 869 self.box.deinit(allocator); 870 } 871 872 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 873 self.clearGrid(); 874 try self.box.build(allocator, constraint, root_focus); 875 } 876 877 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 878 _ = self; 879 _ = allocator; 880 _ = key; 881 _ = root_focus; 882 } 883 884 pub fn clearGrid(self: *Header.View) void { 885 self.box.clearGrid(); 886 } 887 888 pub fn getGrid(self: Header.View) ?Grid { 889 return self.box.getGrid(); 890 } 891 892 pub fn getFocus(self: *Header.View) *Focus { 893 return self.box.getFocus(); 894 } 895 }; 896 }; 897