╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
305 self.getFocus().child_id = box.children.keys()[header_index]; 306 return self; 307 } 308 309 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 310 self.box.deinit(allocator); 311 } 312 313 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 314 self.clearGrid(); 315 const header = &self.box.children.values()[header_index].widget.repo_header; 316 const stack = &self.box.children.values()[stack_index].widget.stack; 317 318 // each header tab maps 1:1 to a stack child by position. mirror the 319 // selection into current_page so the host can push the matching url; 320 // all repo tabs share the .repo parent, so this stays on the page 321 // rather than navigating. 322 if (header.getSelectedIndex()) |index| { 323 stack.getFocus().child_id = stack.children.keys()[index]; 324 switch (std.meta.activeTag(stack.children.values()[index])) { 325 // files/commits carry this page's content route (directory / log 326 // page); settings/auth carry only "owner/name". 327 .repo_commits => self.session.data.current_page = .{ .repo_commits = .{ .name = self.data.commits_route_name, .after = self.data.commits_after } }, 328 // the refs tab mirrors this page's paginated column + offset. 329 .repo_refs => self.session.data.current_page = .{ .repo_refs = .{ .name = self.data.identity, .kind = self.data.refs.kind, .after = self.data.refs.after } }, 330 // the issues tab mirrors this page's tag filter (issue urls 331 // themselves never carry the tag). 332 .repo_issues => self.session.data.current_page = ui.RoutablePage.repoIssuesRoute(self.data.identity.slice(), self.data.issues.tag, "") orelse self.session.data.current_page, 333 .home_settings => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 334 .home_auth => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 335 // the quit tab is tty-only and not a route, so leave current_page 336 // alone (nothing to mirror into the url). 337 .quit => {}, 338 // the files tab (this page's directory route) 339 else => self.session.data.current_page = .{ .repo_files = .{ .name = self.data.route_name, .after = self.data.files_after } }, 340 } 341 } 342 try self.box.build(allocator, constraint, root_focus); 343 } 344 345 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 346 if (self.getFocus().child_id) |child_id| { 347 if (self.box.children.getIndex(child_id)) |current_index| { 348 const child = &self.box.children.values()[current_index].widget; 349 var index = current_index; 350 351 const direction = inp.vertDirection(key); 352 353 switch (direction) { 354 .up => { 355 switch (child.*) { 356 .repo_header => { 357 try child.input(allocator, key, root_focus); 358 }, 359 .stack => { 360 if (child.stack.getSelected()) |selected_widget| { 361 const at_top = switch (selected_widget.*) { 362 .repo_files => |*v| v.getSelectedIndex() == 0, 363 .repo_commits => |*v| v.getSelectedIndex() == 0, 364 .repo_refs => |*v| v.getSelectedIndex() == 0, 365 .repo_issues => |*v| v.getSelectedIndex() == 0, 366 .home_settings => |*v| v.getSelectedIndex() == 0, 367 .home_auth => |*v| v.getSelectedIndex() == 0, 368 .quit => |*v| v.getSelectedIndex() == 0, 369 else => false, 370 }; 371 if (at_top) { 372 index = header_index; 373 } else { 374 try child.input(allocator, key, root_focus); 375 } 376 } 377 }, 378 else => {}, 379 } 380 }, 381 .down => { 382 switch (child.*) { 383 .repo_header => { 384 index = stack_index; 385 }, 386 .stack => { 387 try child.input(allocator, key, root_focus); 388 }, 389 else => {}, 390 } 391 }, 392 .none => { 393 try child.input(allocator, key, root_focus); 394 }, 395 } 396 397 if (index != current_index) { 398 root_focus.setFocus(self.box.children.keys()[index]); 399 } 400 } 401 } 402 } 403 404 pub fn clearGrid(self: *View) void { 405 self.box.clearGrid(); 406 } 407 408 pub fn getGrid(self: View) ?Grid { 409 return self.box.getGrid(); 410 } 411 412 pub fn getFocus(self: *View) *Focus { 413 return self.box.getFocus(); 414 } 415 }; 416