╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
898 self.box.clearGrid(); 899 } 900 901 pub fn getGrid(self: View) ?Grid { 902 return self.box.getGrid(); 903 } 904 905 pub fn getFocus(self: *View) *Focus { 906 return self.box.getFocus(); 907 } 908 909 // for the parent's "scroll up at the top jumps to the header" check. in the 910 // diff pane that means the first hunk is focused and the diff can't scroll up 911 // any further; otherwise up-arrow stays in the pane (scrolling or moving 912 // between hunks). when the list holds focus, report its selection directly. 913 pub fn getSelectedIndex(self: *View) ?usize { 914 if (self.diffActive()) { 915 const inner = self.diffInner(); 916 const cid = inner.getFocus().child_id orelse return 1; 917 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 918 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 919 } 920 const lb = self.listBox(); 921 const cid = lb.getFocus().child_id orelse return null; 922 return lb.children.getIndex(cid); 923 } 924 }; 925 926 // the "a:" navigation link for the commits page walking from commit `oid` within 927 // `identity`, windowing the selected commit's diff from hunk `start`, filtered 928 // to `path` ("" = every file). 929 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 930 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, start, path) orelse return error.RouteTooLong; 931 const url = try route.toUrl(page_arena); 932 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 933 } 934 935 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 936 // directory, within `identity` ("owner/name"). 937 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 938 const route = ui.RoutablePage.repoFilesRoute(identity, .object, oid, "", 0) orelse return error.RouteTooLong; 939 const url = try route.toUrl(page_arena); 940 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 941 } 942 943 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 944 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 945 // in-page (crossPageLink ignores it); the href is only followed with js off. 946 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, path: []const u8) ![]const u8 { 947 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, 0, path) orelse return error.RouteTooLong; 948 const url = try route.toUrl(page_arena); 949 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 950 } 951 952 // the "a:" link to the page showing `oid`'s message on its own. 953 fn messageLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 954 const route = ui.RoutablePage.repoCommitMessageRoute(identity, .object, oid) orelse return error.RouteTooLong; 955 const url = try route.toUrl(page_arena); 956 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 957 } 958 959 // the "viewing <ref_or_oid> <value>" banner shown above the log. 960 pub const Header = struct { 961 content: []const u8, 962 963 // `value` arrives url-encoded, so decode it for display. 964 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 965 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 966 return .{ 967 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), decoded }), 968 }; 969 } 970 971 pub const View = struct { 972 box: wgt.Box(ui.Widget), 973 data: *const Header, 974 975 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 976 _ = session; 977 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 978 errdefer box.deinit(allocator); 979 980 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 981 errdefer text_box.deinit(allocator); 982 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null }); 983 984 return .{ .box = box, .data = data }; 985 } 986 987 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 988 self.box.deinit(allocator); 989 } 990 991 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 992 self.clearGrid(); 993 try self.box.build(allocator, constraint, root_focus); 994 } 995 996 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 997 _ = self; 998 _ = allocator; 999 _ = key; 1000 _ = root_focus; 1001 } 1002 1003 pub fn clearGrid(self: *Header.View) void { 1004 self.box.clearGrid(); 1005 } 1006 1007 pub fn getGrid(self: Header.View) ?Grid { 1008 return self.box.getGrid(); 1009 } 1010 1011 pub fn getFocus(self: *Header.View) *Focus { 1012 return self.box.getFocus(); 1013 } 1014 }; 1015 }; 1016