╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
941 if (self.diffActive()) { 942 const inner = self.diffInner(); 943 const cid = inner.getFocus().child_id orelse return 1; 944 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 945 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 946 } 947 const lb = self.listBox(); 948 const cid = lb.getFocus().child_id orelse return null; 949 return lb.children.getIndex(cid); 950 } 951 }; 952 953 // the "a:" navigation link for the commits page walking from commit `oid` within 954 // `identity`, windowing the selected commit's diff from hunk `start`, filtered 955 // to `path` ("" = every file). 956 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 957 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, start, path) orelse return error.RouteTooLong; 958 const url = try route.toUrl(page_arena); 959 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 960 } 961 962 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 963 // directory, within `identity` ("owner/name"). 964 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 965 const route = ui.RoutablePage.repoFilesRoute(identity, .object, oid, "", 0) orelse return error.RouteTooLong; 966 const url = try route.toUrl(page_arena); 967 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 968 } 969 970 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 971 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 972 // in-page (crossPageLink ignores it); the href is only followed with js off. 973 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, path: []const u8) ![]const u8 { 974 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, 0, path) orelse return error.RouteTooLong; 975 const url = try route.toUrl(page_arena); 976 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 977 } 978 979 // the "a:" link to the page showing `oid`'s message on its own. 980 fn messageLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 981 const route = ui.RoutablePage.repoCommitMessageRoute(identity, .object, oid) orelse return error.RouteTooLong; 982 const url = try route.toUrl(page_arena); 983 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 984 } 985 986 // the "viewing <ref_or_oid> <value>" banner shown above the log. 987 pub const Header = struct { 988 content: []const u8, 989 990 // `value` arrives url-encoded, so decode it for display. 991 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 992 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 993 return .{ 994 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), decoded }), 995 }; 996 } 997 998 pub const View = struct { 999 box: wgt.Box(ui.Widget), 1000 data: *const Header, 1001 1002 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 1003 _ = session; 1004 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1005 errdefer box.deinit(allocator); 1006 1007 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 1008 errdefer text_box.deinit(allocator); 1009 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null }); 1010 1011 return .{ .box = box, .data = data }; 1012 } 1013 1014 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 1015 self.box.deinit(allocator); 1016 } 1017 1018 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1019 self.clearGrid(); 1020 try self.box.build(allocator, constraint, root_focus); 1021 } 1022 1023 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1024 _ = self; 1025 _ = allocator; 1026 _ = key; 1027 _ = root_focus; 1028 } 1029 1030 pub fn clearGrid(self: *Header.View) void { 1031 self.box.clearGrid(); 1032 } 1033 1034 pub fn getGrid(self: Header.View) ?Grid { 1035 return self.box.getGrid(); 1036 } 1037 1038 pub fn getFocus(self: *Header.View) *Focus { 1039 return self.box.getFocus(); 1040 } 1041 }; 1042 }; 1043