╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
268 .header = try Header.init(arena, repo.event.name, owner_name, files.ref_or_oid, files.ref_or_oid_value, issues.tag, patches.tag, discussions.tag), 269 .repo = repo, 270 .files = files, 271 .commits = commits, 272 .refs = refs, 273 .issues = issues, 274 .patches = patches, 275 .discussions = discussions, 276 .events = events, 277 .settings = Settings.init(), 278 .auth = Auth.init(), 279 .quit = Quit.init(), 280 }; 281 } 282 283 pub const View = struct { 284 box: wgt.Box(ui.Widget), 285 286 const header_index: usize = 0; 287 const stack_index: usize = 1; 288 289 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 290 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .rounded_corners = true, .direction = .vert }); 291 errdefer box.deinit(allocator); 292 293 // build the header first so we can grab the files-tab id for the auth 294 // view (it focuses there after login). 295 { 296 var header_view = try Header.View.init(allocator, &data.header, data.commits.commit_count, session); 297 errdefer header_view.deinit(allocator); 298 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .repo_header = header_view }, .rect = null, .min_size = null }); 299 } 300 301 { 302 var stack = try wgt.Stack(ui.Widget).init(allocator); 303 errdefer stack.deinit(allocator); 304 305 // files — the default tab: the current directory's listing. 306 { 307 var files_view = try Files.View.init(allocator, &data.files, session); 308 errdefer files_view.deinit(allocator); 309 try stack.children.put(allocator, files_view.getFocus().id, .{ .repo_files = files_view }); 310 } 311 312 // commits — the current page of the commit log. 313 { 314 var commits_view = try Commits.View.init(allocator, &data.commits, session); 315 errdefer commits_view.deinit(allocator); 316 try stack.children.put(allocator, commits_view.getFocus().id, .{ .repo_commits = commits_view }); 317 } 318 319 // refs — the repo's branches and tags. 320 { 321 var refs_view = try Refs.View.init(allocator, &data.refs, session); 322 errdefer refs_view.deinit(allocator); 323 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 324 } 325 326 // issues — the repo's issue tracker and comment permalinks. 327 { 328 var issues_view = try Issues.View.init(allocator, &data.issues, session); 329 errdefer issues_view.deinit(allocator); 330 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 331 } 332 333 // patches and their comment permalinks. 334 { 335 var patches_view = try Patches.View.init(allocator, &data.patches, session); 336 errdefer patches_view.deinit(allocator); 337 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 338 } 339 340 // discussions and their comment permalinks. 341 { 342 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 343 errdefer discussions_view.deinit(allocator); 344 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 345 } 346 347 { 348 var events_view = try Events.View.init(allocator, &data.events, session); 349 errdefer events_view.deinit(allocator); 350 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 351 } 352 353 // the header only shows the settings tab with a login and the auth 354 // tab outside local mode, so keep the stack's children 1:1 with 355 // the tabs by skipping the same views. 356 if (session.data.user_id != null) { 357 var settings_view = try Settings.View.init(allocator, session); 358 errdefer settings_view.deinit(allocator); 359 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 360 } 361 362 if (!session.data.is_local) { 363 var auth_view = try Auth.View.init(allocator, &data.auth, session); 364 errdefer auth_view.deinit(allocator); 365 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 366 } 367 368 if (session.is_terminal) { 369 var quit_view = try Quit.View.init(allocator, session); 370 errdefer quit_view.deinit(allocator); 371 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 372 } 373 374 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 375 } 376 377 var self = View{ .box = box }; 378 self.getFocus().child_id = box.children.keys()[header_index]; 379 return self; 380 } 381 382 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 383 self.box.deinit(allocator); 384 } 385 386 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 387 self.clearGrid(); 388 const header = &self.box.children.values()[header_index].widget.repo_header; 389 const stack = &self.box.children.values()[stack_index].widget.stack; 390 391 // each header tab maps 1:1 to a stack child by position 392 if (header.getSelectedIndex()) |index| 393 stack.getFocus().child_id = stack.children.keys()[index]; 394 try self.box.build(allocator, constraint, root_focus); 395 } 396 397 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 398 const stack = &self.box.children.values()[stack_index].widget.stack; 399 if (self.getFocus().child_id) |child_id| { 400 if (self.box.children.getIndex(child_id)) |current_index| { 401 const child = &self.box.children.values()[current_index].widget; 402 var index = current_index; 403 404 const direction = inp.vertDirection(key); 405 406 switch (direction) { 407 .up => { 408 switch (child.*) { 409 .repo_header => { 410 try child.input(allocator, key, root_focus); 411 }, 412 .stack => { 413 if (child.stack.getSelected()) |selected_widget| { 414 const at_top = switch (selected_widget.*) { 415 .repo_files => |*v| v.getSelectedIndex() == 0, 416 .repo_commits => |*v| v.getSelectedIndex() == 0, 417 .repo_refs => |*v| v.getSelectedIndex() == 0, 418 .repo_issues => |*v| v.getSelectedIndex() == 0, 419 .repo_patches => |*v| v.getSelectedIndex() == 0, 420 .repo_discussions => |*v| v.getSelectedIndex() == 0, 421 .repo_events => |*v| v.getSelectedIndex() == 0, 422 .home_settings => |*v| v.getSelectedIndex() == 0, 423 .home_auth => |*v| v.getSelectedIndex() == 0, 424 .quit => |*v| v.getSelectedIndex() == 0, 425 else => false, 426 }; 427 if (at_top) { 428 index = header_index; 429 } else { 430 try child.input(allocator, key, root_focus); 431 } 432 } 433 }, 434 else => {}, 435 } 436 }, 437 .down => { 438 switch (child.*) { 439 .repo_header => { 440 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 441 .repo_files => |*v| if (v.focusCloneUrl(root_focus)) return, 442 .repo_commits => |*v| if (v.focusCloneUrl(root_focus)) return, 443 else => {}, 444 }; 445 index = stack_index; 446 }, 447 .stack => { 448 try child.input(allocator, key, root_focus); 449 }, 450 else => {}, 451 } 452 }, 453 .none => { 454 try child.input(allocator, key, root_focus); 455 }, 456 } 457 458 if (index != current_index) { 459 root_focus.setFocus(self.box.children.keys()[index]); 460 } 461 } 462 } 463 } 464 465 pub fn clearGrid(self: *View) void { 466 self.box.clearGrid(); 467 } 468 469 pub fn getGrid(self: View) ?Grid { 470 return self.box.getGrid(); 471 } 472 473 pub fn getFocus(self: *View) *Focus { 474 return self.box.getFocus(); 475 } 476 }; 477