╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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