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