╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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 // discussions and their comment permalinks. 334 { 335 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 336 errdefer discussions_view.deinit(allocator); 337 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 338 } 339 340 { 341 var events_view = try Events.View.init(allocator, &data.events, session); 342 errdefer events_view.deinit(allocator); 343 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 344 } 345 346 // the header only shows the settings tab with a login and the auth 347 // tab outside local mode, so keep the stack's children 1:1 with 348 // the tabs by skipping the same views. 349 if (session.data.user_id != null) { 350 var settings_view = try Settings.View.init(allocator, session); 351 errdefer settings_view.deinit(allocator); 352 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 353 } 354 355 if (!session.data.is_local) { 356 var auth_view = try Auth.View.init(allocator, &data.auth, session); 357 errdefer auth_view.deinit(allocator); 358 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 359 } 360 361 if (session.is_terminal) { 362 var quit_view = try Quit.View.init(allocator, session); 363 errdefer quit_view.deinit(allocator); 364 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 365 } 366 367 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 368 } 369 370 var self = View{ .box = box, .data = data, .session = session }; 371 self.getFocus().child_id = box.children.keys()[header_index]; 372 return self; 373 } 374 375 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 376 self.box.deinit(allocator); 377 } 378 379 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 380 self.clearGrid(); 381 const header = &self.box.children.values()[header_index].widget.repo_header; 382 const stack = &self.box.children.values()[stack_index].widget.stack; 383 384 // each header tab maps 1:1 to a stack child by position. mirror the 385 // selection into current_page so the host can push the matching url; 386 // all repo tabs share the .repo parent, so this stays on the page 387 // rather than navigating. 388 if (header.getSelectedIndex()) |index| { 389 stack.getFocus().child_id = stack.children.keys()[index]; 390 switch (std.meta.activeTag(stack.children.values()[index])) { 391 // files/commits carry this page's content route (directory / log 392 // page); settings/auth carry only "owner/name". 393 .repo_commits => self.session.data.current_page = .{ .repo_commits = self.data.commits_route_name }, 394 // the refs tab mirrors this page's windowed column. 395 .repo_refs => self.session.data.current_page = ui.RoutablePage.repoRefsRoute(self.data.identity.slice(), self.data.refs.kind, self.data.refs.from) orelse self.session.data.current_page, 396 // the issues tab mirrors this page's tag filter (issue urls 397 // themselves never carry the tag). 398 .repo_issues => self.session.data.current_page = ui.RoutablePage.repoIssuesRoute(self.data.identity.slice(), .open, self.data.issues.tag, "") orelse self.session.data.current_page, 399 .repo_discussions => self.session.data.current_page = ui.RoutablePage.repoDiscussionsRoute(self.data.identity.slice(), self.data.discussions.tag, "") orelse self.session.data.current_page, 400 .repo_events => self.session.data.current_page = ui.RoutablePage.repoEventsRoute(self.data.identity.slice(), self.data.events.view, null, "") orelse self.session.data.current_page, 401 .home_settings => { 402 if (ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(self.data.identity.slice())) |identity| 403 self.session.data.current_page = .{ .repo_settings = identity }; 404 }, 405 .home_auth => { 406 if (ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(self.data.identity.slice())) |identity| 407 self.session.data.current_page = .{ .repo_auth = identity }; 408 }, 409 // the quit tab is tty-only and not a route, so leave current_page 410 // alone (nothing to mirror into the url). 411 .quit => {}, 412 // the files tab (this page's directory route) 413 else => self.session.data.current_page = .{ .repo_files = self.data.route_name }, 414 } 415 } 416 try self.box.build(allocator, constraint, root_focus); 417 } 418 419 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 420 const stack = &self.box.children.values()[stack_index].widget.stack; 421 if (self.getFocus().child_id) |child_id| { 422 if (self.box.children.getIndex(child_id)) |current_index| { 423 const child = &self.box.children.values()[current_index].widget; 424 var index = current_index; 425 426 const direction = inp.vertDirection(key); 427 428 switch (direction) { 429 .up => { 430 switch (child.*) { 431 .repo_header => { 432 try child.input(allocator, key, root_focus); 433 }, 434 .stack => { 435 if (child.stack.getSelected()) |selected_widget| { 436 const at_top = switch (selected_widget.*) { 437 .repo_files => |*v| v.getSelectedIndex() == 0, 438 .repo_commits => |*v| v.getSelectedIndex() == 0, 439 .repo_refs => |*v| v.getSelectedIndex() == 0, 440 .repo_issues => |*v| v.getSelectedIndex() == 0, 441 .repo_discussions => |*v| v.getSelectedIndex() == 0, 442 .repo_events => |*v| v.getSelectedIndex() == 0, 443 .home_settings => |*v| v.getSelectedIndex() == 0, 444 .home_auth => |*v| v.getSelectedIndex() == 0, 445 .quit => |*v| v.getSelectedIndex() == 0, 446 else => false, 447 }; 448 if (at_top) { 449 index = header_index; 450 } else { 451 try child.input(allocator, key, root_focus); 452 } 453 } 454 }, 455 else => {}, 456 } 457 }, 458 .down => { 459 switch (child.*) { 460 .repo_header => { 461 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 462 .repo_files => |*v| if (v.focusCloneUrl(root_focus)) return, 463 .repo_commits => |*v| if (v.focusCloneUrl(root_focus)) return, 464 else => {}, 465 }; 466 index = stack_index; 467 }, 468 .stack => { 469 try child.input(allocator, key, root_focus); 470 }, 471 else => {}, 472 } 473 }, 474 .none => { 475 try child.input(allocator, key, root_focus); 476 }, 477 } 478 479 if (index != current_index) { 480 root_focus.setFocus(self.box.children.keys()[index]); 481 } 482 } 483 } 484 } 485 486 pub fn clearGrid(self: *View) void { 487 self.box.clearGrid(); 488 } 489 490 pub fn getGrid(self: View) ?Grid { 491 return self.box.getGrid(); 492 } 493 494 pub fn getFocus(self: *View) *Focus { 495 return self.box.getFocus(); 496 } 497 }; 498