╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
344 }, 345 } 346 347 // refs — the repo's branches and tags. 348 { 349 var refs_view = try Refs.View.init(allocator, &data.refs, session); 350 errdefer refs_view.deinit(allocator); 351 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 352 } 353 354 // issues — the repo's issue tracker and comment permalinks. 355 { 356 var issues_view = try Issues.View.init(allocator, &data.issues, session); 357 errdefer issues_view.deinit(allocator); 358 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 359 } 360 361 // patches and their comment permalinks. 362 { 363 var patches_view = try Patches.View.init(allocator, &data.patches, session); 364 errdefer patches_view.deinit(allocator); 365 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 366 } 367 368 // discussions and their comment permalinks. 369 { 370 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 371 errdefer discussions_view.deinit(allocator); 372 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 373 } 374 375 { 376 var events_view = try Events.View.init(allocator, &data.events, session); 377 errdefer events_view.deinit(allocator); 378 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 379 } 380 381 // the header only shows the settings tab with a login and the auth 382 // tab outside local mode, so keep the stack's children 1:1 with 383 // the tabs by skipping the same views. 384 if (session.data.user_id != null) { 385 var settings_view = try Settings.View.init(allocator, session); 386 errdefer settings_view.deinit(allocator); 387 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 388 } 389 390 if (session.data.host_kind == .server) { 391 var auth_view = try Auth.View.init(allocator, &data.auth, session); 392 errdefer auth_view.deinit(allocator); 393 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 394 } 395 396 if (session.is_terminal) { 397 var quit_view = try Quit.View.init(allocator, session); 398 errdefer quit_view.deinit(allocator); 399 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 400 } 401 402 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 403 } 404 405 var self = View{ .box = box }; 406 self.getFocus().child_id = box.children.keys()[header_index]; 407 return self; 408 } 409 410 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 411 self.box.deinit(allocator); 412 } 413 414 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 415 self.clearGrid(); 416 const header = &self.box.children.values()[header_index].widget.repo_header; 417 const stack = &self.box.children.values()[stack_index].widget.stack; 418 419 // each header tab maps 1:1 to a stack child by position 420 if (header.getSelectedIndex()) |index| 421 stack.getFocus().child_id = stack.children.keys()[index]; 422 try self.box.build(allocator, constraint, root_focus); 423 } 424 425 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 426 const stack = &self.box.children.values()[stack_index].widget.stack; 427 if (self.getFocus().child_id) |child_id| { 428 if (self.box.children.getIndex(child_id)) |current_index| { 429 const child = &self.box.children.values()[current_index].widget; 430 var index = current_index; 431 432 const direction = inp.vertDirection(key); 433 434 switch (direction) { 435 .up => { 436 switch (child.*) { 437 .repo_header => { 438 try child.input(allocator, key, root_focus); 439 }, 440 .stack => { 441 if (child.stack.getSelected()) |selected_widget| { 442 if (selected_widget.atTop(root_focus)) { 443 index = header_index; 444 } else { 445 try child.input(allocator, key, root_focus); 446 } 447 } 448 }, 449 else => {}, 450 } 451 }, 452 .down => { 453 switch (child.*) { 454 .repo_header => { 455 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 456 .repo_files => |*v| if (v.focusCloneUrl(root_focus)) return, 457 .repo_commits => |*v| if (v.focusCloneUrl(root_focus)) return, 458 else => {}, 459 }; 460 index = stack_index; 461 }, 462 .stack => { 463 try child.input(allocator, key, root_focus); 464 }, 465 else => {}, 466 } 467 }, 468 .none => { 469 try child.input(allocator, key, root_focus); 470 }, 471 } 472 473 if (index != current_index) { 474 root_focus.setFocus(self.box.children.keys()[index]); 475 } 476 } 477 } 478 } 479 480 pub fn clearGrid(self: *View) void { 481 self.box.clearGrid(); 482 } 483 484 pub fn getGrid(self: View) ?Grid { 485 return self.box.getGrid(); 486 } 487 488 pub fn getFocus(self: *View) *Focus { 489 return self.box.getFocus(); 490 } 491 }; 492