╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
226 box: wgt.Box(ui.Widget), 227 data: *const Self, 228 session: *ui.Session, 229 230 const header_index: usize = 0; 231 const stack_index: usize = 1; 232 233 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 234 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .rounded_corners = true, .direction = .vert }); 235 errdefer box.deinit(allocator); 236 237 // build the header first so we can grab the files-tab id for the auth 238 // view (it focuses there after login). 239 { 240 var header_view = try Header.View.init(allocator, &data.header, session); 241 errdefer header_view.deinit(allocator); 242 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .repo_header = header_view }, .rect = null, .min_size = null }); 243 } 244 245 { 246 var stack = try wgt.Stack(ui.Widget).init(allocator); 247 errdefer stack.deinit(allocator); 248 249 // files — the default tab: the current directory's listing. 250 { 251 var files_view = try Files.View.init(allocator, &data.files, session); 252 errdefer files_view.deinit(allocator); 253 try stack.children.put(allocator, files_view.getFocus().id, .{ .repo_files = files_view }); 254 } 255 256 // commits — the current page of the commit log. 257 { 258 var commits_view = try Commits.View.init(allocator, &data.commits, session); 259 errdefer commits_view.deinit(allocator); 260 try stack.children.put(allocator, commits_view.getFocus().id, .{ .repo_commits = commits_view }); 261 } 262 263 // refs — the repo's branches and tags. 264 { 265 var refs_view = try Refs.View.init(allocator, &data.refs, session); 266 errdefer refs_view.deinit(allocator); 267 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 268 } 269 270 // issues — the repo's issue tracker. 271 { 272 var issues_view = try Issues.View.init(allocator, &data.issues, session); 273 errdefer issues_view.deinit(allocator); 274 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 275 } 276 277 // the header only shows the settings tab with a login and the auth 278 // tab outside local mode, so keep the stack's children 1:1 with 279 // the tabs by skipping the same views. 280 if (session.data.user_id != null) { 281 var settings_view = try Settings.View.init(allocator, session); 282 errdefer settings_view.deinit(allocator); 283 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 284 } 285 286 if (!session.data.is_local) { 287 var auth_view = try Auth.View.init(allocator, &data.auth, session); 288 errdefer auth_view.deinit(allocator); 289 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 290 } 291 292 if (session.is_terminal) { 293 var quit_view = try Quit.View.init(allocator, session); 294 errdefer quit_view.deinit(allocator); 295 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 296 } 297 298 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 299 } 300 301 var self = View{ .box = box, .data = data, .session = session }; 302 self.getFocus().child_id = box.children.keys()[header_index]; 303 return self; 304 } 305 306 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 307 self.box.deinit(allocator); 308 } 309 310 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 311 self.clearGrid(); 312 const header = &self.box.children.values()[header_index].widget.repo_header; 313 const stack = &self.box.children.values()[stack_index].widget.stack; 314 315 // each header tab maps 1:1 to a stack child by position. mirror the 316 // selection into current_page so the host can push the matching url; 317 // all repo tabs share the .repo parent, so this stays on the page 318 // rather than navigating. 319 if (header.getSelectedIndex()) |index| { 320 stack.getFocus().child_id = stack.children.keys()[index]; 321 switch (std.meta.activeTag(stack.children.values()[index])) { 322 // files/commits carry this page's content route (directory / log 323 // page); settings/auth carry only "owner/name". 324 .repo_commits => self.session.data.current_page = .{ .repo_commits = self.data.commits_route_name }, 325 // the refs tab mirrors this page's windowed column. 326 .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, 327 // the issues tab mirrors this page's tag filter (issue urls 328 // themselves never carry the tag). 329 .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, 330 .home_settings => { 331 if (ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(self.data.identity.slice())) |identity| 332 self.session.data.current_page = .{ .repo_settings = identity }; 333 }, 334 .home_auth => { 335 if (ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(self.data.identity.slice())) |identity| 336 self.session.data.current_page = .{ .repo_auth = identity }; 337 }, 338 // the quit tab is tty-only and not a route, so leave current_page 339 // alone (nothing to mirror into the url). 340 .quit => {}, 341 // the files tab (this page's directory route) 342 else => self.session.data.current_page = .{ .repo_files = self.data.route_name }, 343 } 344 } 345 try self.box.build(allocator, constraint, root_focus); 346 } 347 348 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 349 if (self.getFocus().child_id) |child_id| { 350 if (self.box.children.getIndex(child_id)) |current_index| { 351 const child = &self.box.children.values()[current_index].widget; 352 var index = current_index; 353 354 const direction = inp.vertDirection(key); 355 356 switch (direction) { 357 .up => { 358 switch (child.*) { 359 .repo_header => { 360 try child.input(allocator, key, root_focus); 361 }, 362 .stack => { 363 if (child.stack.getSelected()) |selected_widget| { 364 const at_top = switch (selected_widget.*) { 365 .repo_files => |*v| v.getSelectedIndex() == 0, 366 .repo_commits => |*v| v.getSelectedIndex() == 0, 367 .repo_refs => |*v| v.getSelectedIndex() == 0, 368 .repo_issues => |*v| v.getSelectedIndex() == 0, 369 .home_settings => |*v| v.getSelectedIndex() == 0, 370 .home_auth => |*v| v.getSelectedIndex() == 0, 371 .quit => |*v| v.getSelectedIndex() == 0, 372 else => false, 373 }; 374 if (at_top) { 375 index = header_index; 376 } else { 377 try child.input(allocator, key, root_focus); 378 } 379 } 380 }, 381 else => {}, 382 } 383 }, 384 .down => { 385 switch (child.*) { 386 .repo_header => { 387 index = stack_index; 388 }, 389 .stack => { 390 try child.input(allocator, key, root_focus); 391 }, 392 else => {}, 393 } 394 }, 395 .none => { 396 try child.input(allocator, key, root_focus); 397 }, 398 } 399 400 if (index != current_index) { 401 root_focus.setFocus(self.box.children.keys()[index]); 402 } 403 } 404 } 405 } 406 407 pub fn clearGrid(self: *View) void { 408 self.box.clearGrid(); 409 } 410 411 pub fn getGrid(self: View) ?Grid { 412 return self.box.getGrid(); 413 } 414 415 pub fn getFocus(self: *View) *Focus { 416 return self.box.getFocus(); 417 } 418 }; 419