╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
934 return first_focused and self.diffScroll().y == 0; 935 } 936 const lb = self.listBox(); 937 const cid = lb.getFocus().child_id orelse return true; 938 return lb.children.getIndex(cid) == 0; 939 } 940 941 // only the clone-url row sits directly below the repository header. 942 pub fn getSelectedIndex(self: *View) ?usize { 943 if (self.headerActive()) return 0; 944 return if (self.header().hasCloneUrl() or !self.contentAtTop()) 1 else 0; 945 } 946 947 pub fn focusCloneUrl(self: *View, root_focus: *Focus) bool { 948 return self.header().focusCloneUrl(root_focus); 949 } 950 }; 951 952 // the "a:" navigation link for the commits page walking from commit `oid` within 953 // `location`, windowing the selected commit's diff from hunk `start`, filtered 954 // to `path` ("" = every file). 955 fn commitsLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 956 const route = location.commitsRoute(.object, oid, start, path) orelse return error.RouteTooLong; 957 const url = try route.toUrl(page_arena); 958 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 959 } 960 961 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 962 // directory, within `location`. 963 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 964 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 965 const url = try route.toUrl(page_arena); 966 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 967 } 968 969 // the in-page "ai:" anchor for selecting a commit with its current pane content 970 // and window. the href is only followed with js off. 971 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, commit: Commit, content: Content) ![]const u8 { 972 const route = (switch (content) { 973 .message => location.commitMessageRoute(.object, commit.oid), 974 .diff => |diff| location.commitsRoute(.object, commit.oid, commit.window_start, diff.path), 975 }) orelse return error.RouteTooLong; 976 const url = try route.toUrl(page_arena); 977 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 978 } 979 980 // the "a:" link to the page showing `oid`'s message on its own. 981 fn messageLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 982 const route = location.commitMessageRoute(.object, oid) orelse return error.RouteTooLong; 983 const url = try route.toUrl(page_arena); 984 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 985 } 986 987 // the "<ref_or_oid> <value>" banner shown above the log. 988 pub const Header = struct { 989 content: []const u8, 990 991 // `value` arrives url-encoded, so decode it for display. 992 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 993 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 994 return .{ 995 .content = try std.fmt.allocPrint(aa, "{s} {s}", .{ @tagName(ref_or_oid), decoded }), 996 }; 997 } 998 999 pub const View = struct { 1000 box: wgt.Box(ui.Widget), 1001 data: *const Header, 1002 1003 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session, location: ui.RoutablePage.RepoLocation) !Header.View { 1004 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1005 errdefer box.deinit(allocator); 1006 1007 if (!session.data.is_local) { 1008 if (try ui.widget.CopyableText.initClone(allocator, session, location)) |value| { 1009 var clone_url = value; 1010 errdefer clone_url.deinit(allocator); 1011 const min_width = clone_url.minWidth(); 1012 box.getFocus().child_id = clone_url.getFocus().id; 1013 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 } }); 1014 } 1015 } 1016 1017 var spacer = try ui.widget.Spacer.init(allocator); 1018 errdefer spacer.deinit(allocator); 1019 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1020 1021 var text_box = try wgt.TextBox.init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 1022 errdefer text_box.deinit(allocator); 1023 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null, .flex = .shrink }); 1024 1025 return .{ .box = box, .data = data }; 1026 } 1027 1028 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 1029 self.box.deinit(allocator); 1030 } 1031 1032 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1033 self.clearGrid(); 1034 try self.box.build(allocator, constraint, root_focus); 1035 } 1036 1037 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1038 const clone_url = self.cloneUrl() orelse return; 1039 try clone_url.input(allocator, key, root_focus); 1040 } 1041 1042 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 1043 const clone_url = self.cloneUrl() orelse return false; 1044 root_focus.setFocus(clone_url.getFocus().id); 1045 return true; 1046 } 1047 1048 pub fn hasCloneUrl(self: *Header.View) bool { 1049 return self.cloneUrl() != null; 1050 } 1051 1052 fn cloneUrl(self: *Header.View) ?*ui.widget.CopyableText { 1053 for (self.box.children.values()) |*child| switch (child.widget) { 1054 .copyable_text => |*copyable_text| return copyable_text, 1055 else => {}, 1056 }; 1057 return null; 1058 } 1059 1060 pub fn clearGrid(self: *Header.View) void { 1061 self.box.clearGrid(); 1062 } 1063 1064 pub fn getGrid(self: Header.View) ?Grid { 1065 return self.box.getGrid(); 1066 } 1067 1068 pub fn getFocus(self: *Header.View) *Focus { 1069 return self.box.getFocus(); 1070 } 1071 }; 1072 }; 1073