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