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