╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
187 try Refs.emptyResult(arena, rf.identity, refs_kind, refs_after), 188 try Issues.emptyResult(aa, rf.identity, issues_tag, issues_selected), 189 }; 190 }; 191 192 // each tab mirror carries this page's route for that tab; tabs not targeted 193 // by the incoming route fall back to their root/first-page route. the files 194 // mirror carries the selected file (when the route named one) so the url 195 // keeps it before focus enters the view. 196 const files_path = if (files.selected_file) |f| try Files.childDir(arena.allocator(), files.dir, f) else files.dir; 197 // the content window offset only applies to a selected file, so the bare 198 // directory route drops it. 199 const files_route_after = if (files.selected_file != null) files_after else 0; 200 const route_name = (ui.RoutablePage.repoFilesRoute(rf.identity, files.ref_or_oid, files.ref_or_oid_value, files_path, files_route_after) orelse return error.NotFound).repo_files.name; 201 const commits_route_name = (ui.RoutablePage.repoCommitsRoute(rf.identity, commits.ref_or_oid, commits.ref_or_oid_value, commits_after) orelse return error.NotFound).repo_commits.name; 202 203 return .{ 204 // files and commits resolve the same ref, so either's serves the header, 205 // which points both tabs at it. 206 .header = try Header.init(arena, repo.name, owner_name, files.ref_or_oid, files.ref_or_oid_value, issues_tag), 207 .repo = repo, 208 .files = files, 209 .commits = commits, 210 .refs = refs, 211 .issues = issues, 212 .settings = Settings.init(), 213 .auth = Auth.init(), 214 .quit = Quit.init(), 215 .route_name = route_name, 216 .files_after = files_route_after, 217 .commits_route_name = commits_route_name, 218 .commits_after = commits_after, 219 .identity = Array.from(rf.identity) orelse return error.NotFound, 220 }; 221 } 222 223 pub const View = struct { 224 box: wgt.Box(ui.Widget), 225 data: *const Self, 226 session: *ui.Session, 227 228 const header_index: usize = 0; 229 const stack_index: usize = 1; 230 231 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 232 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .rounded_corners = true, .direction = .vert }); 233 errdefer box.deinit(allocator); 234 235 // build the header first so we can grab the files-tab id for the auth 236 // view (it focuses there after login). 237 var files_tab_id: usize = undefined; 238 { 239 var header_view = try Header.View.init(allocator, &data.header, session); 240 errdefer header_view.deinit(allocator); 241 files_tab_id = header_view.tab_ids.keys()[0]; 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 { 278 var settings_view = try Settings.View.init(allocator, session); 279 errdefer settings_view.deinit(allocator); 280 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 281 } 282 283 // the header has no auth tab in local mode, so keep the stack's 284 // children 1:1 with the tabs by skipping the auth view too. 285 if (!session.data.is_local) { 286 var auth_view = try Auth.View.init(allocator, &data.auth, session, files_tab_id); 287 errdefer auth_view.deinit(allocator); 288 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 289 } 290 291 if (session.is_terminal) { 292 var quit_view = try Quit.View.init(allocator, session); 293 errdefer quit_view.deinit(allocator); 294 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 295 } 296 297 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 298 } 299 300 var self = View{ .box = box, .data = data, .session = session }; 301 self.getFocus().child_id = box.children.keys()[header_index]; 302 return self; 303 } 304 305 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 306 self.box.deinit(allocator); 307 } 308 309 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 310 self.clearGrid(); 311 const header = &self.box.children.values()[header_index].widget.repo_header; 312 const stack = &self.box.children.values()[stack_index].widget.stack; 313 314 // each header tab maps 1:1 to a stack child by position. mirror the 315 // selection into current_page so the host can push the matching url; 316 // all repo tabs share the .repo parent, so this stays on the page 317 // rather than navigating. 318 if (header.getSelectedIndex()) |index| { 319 stack.getFocus().child_id = stack.children.keys()[index]; 320 switch (std.meta.activeTag(stack.children.values()[index])) { 321 // files/commits carry this page's content route (directory / log 322 // page); settings/auth carry only "owner/name". 323 .repo_commits => self.session.data.current_page = .{ .repo_commits = .{ .name = self.data.commits_route_name, .after = self.data.commits_after } }, 324 // the refs tab mirrors this page's paginated column + offset. 325 .repo_refs => self.session.data.current_page = .{ .repo_refs = .{ .name = self.data.identity, .kind = self.data.refs.kind, .after = self.data.refs.after } }, 326 // the issues tab mirrors this page's tag filter (issue urls 327 // themselves never carry the tag). 328 .repo_issues => self.session.data.current_page = ui.RoutablePage.repoIssuesRoute(self.data.identity.slice(), self.data.issues.tag, "") orelse self.session.data.current_page, 329 .home_settings => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 330 .home_auth => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 331 // the quit tab is tty-only and not a route, so leave current_page 332 // alone (nothing to mirror into the url). 333 .quit => {}, 334 // the files tab (this page's directory route) 335 else => self.session.data.current_page = .{ .repo_files = .{ .name = self.data.route_name, .after = self.data.files_after } }, 336 } 337 } 338 try self.box.build(allocator, constraint, root_focus); 339 } 340 341 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 342 if (self.getFocus().child_id) |child_id| { 343 if (self.box.children.getIndex(child_id)) |current_index| { 344 const child = &self.box.children.values()[current_index].widget; 345 var index = current_index; 346 347 const direction = inp.vertDirection(key); 348 349 switch (direction) { 350 .up => { 351 switch (child.*) { 352 .repo_header => { 353 try child.input(allocator, key, root_focus); 354 }, 355 .stack => { 356 if (child.stack.getSelected()) |selected_widget| { 357 const at_top = switch (selected_widget.*) { 358 .repo_files => |*v| v.getSelectedIndex() == 0, 359 .repo_commits => |*v| v.getSelectedIndex() == 0, 360 .repo_refs => |*v| v.getSelectedIndex() == 0, 361 .repo_issues => |*v| v.getSelectedIndex() == 0, 362 .home_settings => |*v| v.getSelectedIndex() == 0, 363 .home_auth => |*v| v.getSelectedIndex() == 0, 364 .quit => |*v| v.getSelectedIndex() == 0, 365 else => false, 366 }; 367 if (at_top) { 368 index = header_index; 369 } else { 370 try child.input(allocator, key, root_focus); 371 } 372 } 373 }, 374 else => {}, 375 } 376 }, 377 .down => { 378 switch (child.*) { 379 .repo_header => { 380 index = stack_index; 381 }, 382 .stack => { 383 try child.input(allocator, key, root_focus); 384 }, 385 else => {}, 386 } 387 }, 388 .none => { 389 try child.input(allocator, key, root_focus); 390 }, 391 } 392 393 if (index != current_index) { 394 root_focus.setFocus(self.box.children.keys()[index]); 395 } 396 } 397 } 398 } 399 400 pub fn clearGrid(self: *View) void { 401 self.box.clearGrid(); 402 } 403 404 pub fn getGrid(self: View) ?Grid { 405 return self.box.getGrid(); 406 } 407 408 pub fn getFocus(self: *View) *Focus { 409 return self.box.getFocus(); 410 } 411 }; 412