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