╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
152 const diff_oid: []const u8, const diff_base_oid: []const u8 = switch (route) { 153 .fork_diff => |*d| .{ try aa.dupe(u8, d.oid.slice()), try aa.dupe(u8, d.base_oid.slice()) }, 154 else => .{ "", "" }, 155 }; 156 const diff_base: ?@TypeOf(fork_oid), const diff_head: @TypeOf(fork_oid) = if (diff_oid.len == 0) .{ commits_base_oid, fork_oid } else named: { 157 evt.PatchRev.validateOid(repo_opts.hash, diff_oid) catch return error.NotFound; 158 evt.PatchRev.validateOid(repo_opts.hash, diff_base_oid) catch return error.NotFound; 159 break :named .{ if (std.mem.allEqual(u8, diff_base_oid, '0')) null else diff_base_oid[0..fork_oid.len].*, diff_oid[0..fork_oid.len].* }; 160 }; 161 162 return .{ 163 .header = try Header.init(arena, target_record.event.name, identity.owner, &id_hex, requested_value), 164 .files = files, 165 .commits = commits, 166 .patch = patch_data, 167 .diff = .{ 168 .route = .{ .fork = .{ .identity = try aa.dupe(u8, identity.identity), .id = try aa.dupe(u8, &id_hex), .oid = diff_oid, .base_oid = diff_base_oid } }, 169 .path = diff_path, 170 .window = try Diff.render(.xit, repo_opts, io, arena.child_allocator, aa, fork_repo, if (diff_base) |*base| base else null, diff_head, diff_start, diff_path), 171 }, 172 .quit = Quit.init(), 173 }; 174 }, 175 } 176 } 177 178 pub const View = struct { 179 box: wgt.Box(ui.Widget), 180 181 const header_index: usize = 0; 182 const stack_index: usize = 1; 183 184 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 185 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 186 errdefer box.deinit(allocator); 187 { 188 var header = try Header.View.init(allocator, &data.header, data.commits.commit_count, session); 189 errdefer header.deinit(allocator); 190 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 191 } 192 { 193 var stack = try wgt.Stack(ui.Widget).init(allocator); 194 errdefer stack.deinit(allocator); 195 const selected = data.patch.selectedThread() orelse return error.NotFound; 196 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 197 errdefer patch_detail.deinit(allocator); 198 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 199 { 200 var diff = try Diff.View.init(allocator, &data.diff, session); 201 errdefer diff.deinit(allocator); 202 try stack.children.put(allocator, diff.getFocus().id, .{ .diff_view = diff }); 203 } 204 { 205 var files = try Files.View.init(allocator, &data.files, session); 206 errdefer files.deinit(allocator); 207 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 208 } 209 { 210 var commits = try Commits.View.init(allocator, &data.commits, session); 211 errdefer commits.deinit(allocator); 212 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 213 } 214 const identity = try std.fmt.allocPrint(session.page_arena.allocator(), "{s}:{s}", .{ data.header.forker_name, data.header.name }); 215 if (session.data.user_id != null) { 216 const route = ui.RoutablePage.forkRepoNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 217 var new_repo = try ui.NewRepo.View.init(allocator, session, route); 218 errdefer new_repo.deinit(allocator); 219 try stack.children.put(allocator, new_repo.getFocus().id, .{ .new_repo = new_repo }); 220 } else if (session.data.host_kind == .server) { 221 const route = ui.RoutablePage.forkUserNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 222 var new_user = try ui.NewUser.View.init(allocator, session, route); 223 errdefer new_user.deinit(allocator); 224 try stack.children.put(allocator, new_user.getFocus().id, .{ .new_user = new_user }); 225 } 226 if (session.data.host_kind == .server) { 227 var user_view = try ui.UserLogout.initView(allocator, session); 228 errdefer user_view.deinit(allocator); 229 try stack.children.put(allocator, user_view.getFocus().id, user_view); 230 } 231 if (session.is_terminal) { 232 var quit = try Quit.View.init(allocator, session); 233 errdefer quit.deinit(allocator); 234 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 235 } 236 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 237 } 238 // a page opens on its tabs, except that search results open in the 239 // files tab's search box. 240 box.getFocus().child_id = box.children.keys()[if (data.files.find != null) stack_index else header_index]; 241 return .{ .box = box }; 242 } 243 244 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 245 self.box.deinit(allocator); 246 } 247 248 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 249 self.clearGrid(); 250 const header = &self.box.children.values()[header_index].widget.fork_header; 251 const stack = &self.box.children.values()[stack_index].widget.stack; 252 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 253 try self.box.build(allocator, constraint, root_focus); 254 } 255 256 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 257 const stack = &self.box.children.values()[stack_index].widget.stack; 258 const current_id = self.box.getFocus().child_id orelse return; 259 const current_index = self.box.children.getIndex(current_id) orelse return; 260 const child = &self.box.children.values()[current_index].widget; 261 var next_index = current_index; 262 switch (inp.vertDirection(key)) { 263 .up => switch (child.*) { 264 .fork_header => try child.input(allocator, key, root_focus), 265 .stack => if (stack.getSelected()) |selected| { 266 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 267 }, 268 else => {}, 269 }, 270 .down => switch (child.*) { 271 .fork_header => { 272 if (stack.getSelected()) |selected| switch (selected.*) { 273 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 274 .repo_files => |*view| if (view.focusHeader(root_focus)) return, 275 .repo_commits => |*view| if (view.focusHeader(root_focus)) return, 276 else => {}, 277 }; 278 next_index = stack_index; 279 }, 280 .stack => try child.input(allocator, key, root_focus), 281 else => {}, 282 }, 283 .none => try child.input(allocator, key, root_focus), 284 } 285 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 286 } 287 288 pub fn clearGrid(self: *View) void { 289 self.box.clearGrid(); 290 } 291 292 pub fn getGrid(self: View) ?Grid { 293 return self.box.getGrid(); 294 } 295 296 pub fn getFocus(self: *View) *Focus { 297 return self.box.getFocus(); 298 } 299 }; 300