╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../event.zig"); 3 const pch = @import("../patch.zig"); 4 const ui = @import("../ui.zig"); 5 const xit = @import("xit"); 6 const rp = xit.repo; 7 const xitui = xit.xitui; 8 const wgt = xitui.widget; 9 const layout = xitui.layout; 10 const Key = xitui.input.Key; 11 const Grid = xitui.grid.Grid; 12 const Focus = xitui.focus.Focus; 13 const inp = @import("./input.zig"); 14 15 pub const Header = @import("./Repo/Header.zig"); 16 pub const Files = @import("./Repo/Files.zig"); 17 pub const Commits = @import("./Repo/Commits.zig"); 18 pub const Diff = @import("./Repo/Diff.zig"); 19 pub const Refs = @import("./Repo/Refs.zig"); 20 pub const Issues = @import("./Repo/Issues.zig"); 21 pub const Patches = @import("./Repo/Patches.zig"); 22 pub const Discussions = @import("./Repo/Discussions.zig"); 23 pub const Comment = @import("./Repo/Comment.zig"); 24 pub const Events = @import("./Repo/Events.zig"); 25 pub const Settings = @import("./Settings.zig"); 26 pub const Auth = @import("./Auth.zig"); 27 pub const Quit = @import("./Quit.zig"); 28 29 header: Header, 30 repo: evt.Repo.Record, 31 files: Files, 32 changes: Changes, 33 refs: Refs, 34 issues: Issues, 35 patches: Patches, 36 discussions: Discussions, 37 events: Events, 38 settings: Settings, 39 auth: Auth, 40 quit: Quit, 41 42 const Self = @This(); 43 44 const Changes = union(enum) { 45 commits: Commits, 46 diff: Diff, 47 }; 48 49 pub fn init( 50 arena: *std.heap.ArenaAllocator, 51 session: *ui.Session, 52 route: ui.RoutablePage, 53 ) !Self { 54 const DB = evt.AdminDB; 55 const hash_kind = evt.admin_repo_opts.hash; 56 57 // every repo route stores its identity as "owner/name" (or elides it in local mode) 58 const name_str = route.repoIdentity() orelse return error.UnexpectedRoute; 59 const repo_identity = ui.RoutablePage.RepoIdentity.parse(name_str) orelse return error.NotFound; 60 const location = ui.RoutablePage.RepoLocation{ .repo = repo_identity.identity }; 61 // files, commits and diff share the requested ref, or the default branch. 62 // directories and hunk windows only apply to their own tab. 63 const requested_ref_or_oid: ?ui.RoutablePage.RefOrOid = switch (route) { 64 .repo_files => |f| f.ref_kind, 65 .repo_commits => |c| c.ref_or_oid, 66 .repo_diff => |d| d.ref_or_oid, 67 else => null, 68 }; 69 const requested_ref_value: []const u8 = switch (route) { 70 .repo_files => |*f| f.ref_value.slice(), 71 .repo_commits => |*c| c.value.slice(), 72 .repo_diff => |*d| d.value.slice(), 73 else => "", 74 }; 75 const patchrev_id: []const u8 = switch (route) { 76 .repo_files => |*f| f.patchrev_id.slice(), 77 .repo_diff => |*d| d.patchrev_id.slice(), 78 else => "", 79 }; 80 const files_dir = switch (route) { 81 .repo_files => |*f| f.path.slice(), 82 else => "", 83 }; 84 const files_line = switch (route) { 85 .repo_files => |f| f.line, 86 else => 0, 87 }; 88 const files_find: []const u8 = switch (route) { 89 .repo_files => |*f| f.find.slice(), 90 else => "", 91 }; 92 // what the commits view's pane shows for the commit it walks from: a diff 93 // window (with the file it's filtered to) or that commit's message. 94 const commits_content: ui.RoutablePage.RepoCommitsRoute.Content = switch (route) { 95 .repo_commits => |c| c.content, 96 else => .{ .diff = .{} }, 97 }; 98 const commits_base_oid: []const u8 = switch (route) { 99 .repo_commits => |*c| c.base_oid.slice(), 100 else => "", 101 }; 102 const commits_search: []const u8 = switch (route) { 103 .repo_commits => |*c| c.search.slice(), 104 else => "", 105 }; 106 const commits_from: []const u8 = switch (route) { 107 .repo_commits => |*c| c.from.slice(), 108 else => "", 109 }; 110 // the refs tab windows one column at a time: `refs_from` (a url-encoded 111 // ref name) roots `refs_kind`'s column, the other stays at its first window. 112 const refs_kind: ui.RoutablePage.RefKind = switch (route) { 113 .repo_refs => |r| r.kind, 114 else => .branch, 115 }; 116 const refs_from: []const u8 = switch (route) { 117 .repo_refs => |*r| r.from.slice(), 118 else => "", 119 }; 120 // the issues tab's tag filter, the issue its window is rooted at, and the 121 // view it shows. 122 const issues_tag: []const u8 = switch (route) { 123 .repo_issues => |*i| i.tag.slice(), 124 else => "", 125 }; 126 const issues_selected: []const u8 = switch (route) { 127 .repo_issues => |*i| i.selected.slice(), 128 else => "", 129 }; 130 const issues_comment: []const u8 = switch (route) { 131 .repo_issues => |*i| i.comment.slice(), 132 else => "", 133 }; 134 const issues_theirs: []const u8 = switch (route) { 135 .repo_issues => |*i| i.theirs.slice(), 136 else => "", 137 }; 138 const issues_view: ui.RoutablePage.IssuesView = switch (route) { 139 .repo_issues => |i| i.view, 140 else => .open, 141 }; 142 const issues_comments_start: usize = switch (route) { 143 .repo_issues => |i| i.comments_start, 144 else => 0, 145 }; 146 const patches_tag: []const u8 = switch (route) { 147 .repo_patches => |*p| p.tag.slice(), 148 else => "", 149 }; 150 const patches_selected: []const u8 = switch (route) { 151 .repo_patches => |*p| p.selected.slice(), 152 else => "", 153 }; 154 const patches_comment: []const u8 = switch (route) { 155 .repo_patches => |*p| p.comment.slice(), 156 else => "", 157 }; 158 const patches_theirs: []const u8 = switch (route) { 159 .repo_patches => |*p| p.theirs.slice(), 160 else => "", 161 }; 162 const patches_view: ui.RoutablePage.PatchesView = switch (route) { 163 .repo_patches => |p| p.view, 164 else => .open, 165 }; 166 const patches_comments_start: usize = switch (route) { 167 .repo_patches => |p| p.comments_start, 168 else => 0, 169 }; 170 const discussions_tag: []const u8 = switch (route) { 171 .repo_discussions => |*t| t.tag.slice(), 172 else => "", 173 }; 174 const discussions_selected: []const u8 = switch (route) { 175 .repo_discussions => |*t| t.selected.slice(), 176 else => "", 177 }; 178 const discussions_comment: []const u8 = switch (route) { 179 .repo_discussions => |*t| t.comment.slice(), 180 else => "", 181 }; 182 const discussions_view: ui.RoutablePage.DiscussionsView = switch (route) { 183 .repo_discussions => |t| t.view, 184 else => .recent, 185 }; 186 const discussions_comments_start: usize = switch (route) { 187 .repo_discussions => |t| t.comments_start, 188 else => 0, 189 }; 190 const events_kind: ?evt.EventKind = switch (route) { 191 .repo_events => |e| e.kind, 192 else => null, 193 }; 194 const events_view: ui.RoutablePage.EventsView = switch (route) { 195 .repo_events => |e| e.view, 196 else => .active, 197 }; 198 const events_selected: []const u8 = switch (route) { 199 .repo_events => |*e| e.selected.slice(), 200 else => "", 201 }; 202 203 // where the on-disk repo lives (null keeps the views' empty fallback), plus 204 // the repo and owner-name metadata the header shows. local mode already 205 // knows all three; the server paths resolve them from the admin db. 206 var source: ?ui.RepoSource = null; 207 var repo_id_maybe: ?[evt.event_id_size]u8 = null; 208 var repo: evt.Repo.Record = undefined; 209 var owner_name: []const u8 = undefined; 210 if (session.local) |local| { 211 source = local; 212 // local routes elide the identity, so the display name comes from the 213 // repo's directory rather than the route. 214 repo = .{ .event = .{ 215 .user_id = "", 216 .name = try arena.allocator().dupe(u8, std.fs.path.basename(local.path)), 217 .description = "", 218 } }; 219 owner_name = ""; 220 } else { 221 const haxy_moment = session.haxy_moment orelse return error.NoMoment; 222 const found = (try evt.Repo.readByOwnerAndName(DB, hash_kind, haxy_moment, arena, repo_identity.owner, repo_identity.name)) orelse return error.NotFound; 223 // a repo the session can't read doesn't exist to it 224 if (evt.Repo.roleOf(found.repo, session.userId()) == .none) return error.NotFound; 225 repo = found.repo; 226 repo_id_maybe = found.event_id; 227 228 // resolve the creating user so the header can show their name to the left 229 // of the repo title. 230 const owner = (try evt.User.readById(DB, hash_kind, haxy_moment, arena, repo.event.user_id)) orelse return error.NotFound; 231 owner_name = owner.event.name; 232 233 // the repo's working copy lives at <repos_dir>/<hex event id>. 234 if (session.repos_dir) |repos_dir| { 235 const hex = std.fmt.bytesToHex(found.event_id, .lower); 236 source = .{ 237 .path = try std.fs.path.join(arena.allocator(), &.{ repos_dir, &hex }), 238 .repo_kind = .xit, 239 }; 240 } 241 } 242 243 // open the repo once for every tab. files and changes share a ref or revision. 244 // no filesystem (wasm), nowhere to look, or a failed open: empty tabs. 245 const files, const changes, const refs, var issues, var patches, var discussions, const events = blk: { 246 read: { 247 const io = session.io orelse break :read; 248 const src = source orelse break :read; 249 const gpa = arena.child_allocator; 250 switch (src.repo_kind) { 251 inline else => |repo_kind| { 252 var any_repo = rp.AnyRepo(repo_kind, .{}).open(io, gpa, src.localInitOpts()) catch break :read; 253 defer any_repo.deinit(io, gpa); 254 switch (any_repo) { 255 inline else => |*opened| { 256 // local mode: bring the event db up to date with the events branch 257 if (session.local != null) { 258 try evt.consume(.local, .repo, repo_kind, opened.self_repo_opts, io, gpa, opened, evt.events_ref, &.{}); 259 try pch.refreshBranches(.local, repo_kind, opened.self_repo_opts, io, gpa, opened, null, null); 260 } 261 const files_data = if (patchrev_id.len != 0) 262 try Files.initPatchRev(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, location, patchrev_id, files_dir, files_line) 263 else 264 try Files.init(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, location, requested_ref_or_oid, requested_ref_value, files_dir, files_line, files_find); 265 const changes_data: Changes = if (route == .repo_diff) 266 .{ .diff = try Diff.init(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, route.repo_diff) } 267 else if (patchrev_id.len != 0) diff: { 268 const diff_route = ui.RoutablePage.repoPatchRevDiffRoute(repo_identity.identity, patchrev_id, 0, "") orelse return error.RouteTooLong; 269 break :diff .{ .diff = try Diff.init(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, diff_route.repo_diff) }; 270 } else .{ .commits = try Commits.init(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, session.haxy_moment, location, requested_ref_or_oid, requested_ref_value, commits_content, commits_base_oid, commits_search, commits_from) }; 271 const target_branch = if (files_data.ref_or_oid == .branch) files_data.ref_or_oid_value else ""; 272 break :blk .{ 273 files_data, 274 changes_data, 275 try Refs.init(repo_kind, opened.self_repo_opts, arena, opened, io, gpa, repo_identity.identity, refs_kind, refs_from), 276 try Issues.init(repo_kind, opened.self_repo_opts, arena, opened, io, session.haxy_moment, repo_identity.identity, issues_tag, issues_selected, issues_comment, issues_comments_start, issues_theirs, issues_view), 277 try Patches.init(repo_kind, opened.self_repo_opts, arena, opened, io, session.haxy_moment, session, repo_id_maybe, repo_identity.identity, target_branch, patches_tag, patches_selected, patches_comment, patches_comments_start, patches_theirs, patches_view), 278 try Discussions.init(repo_kind, opened.self_repo_opts, arena, opened, io, session.haxy_moment, repo_identity.identity, discussions_tag, discussions_selected, discussions_comment, discussions_comments_start, discussions_view), 279 try Events.init(repo_kind, opened.self_repo_opts, arena, opened, io, session.haxy_moment, repo_identity.identity, events_view, events_kind, events_selected, session.local != null, session.data.sync_failure), 280 }; 281 }, 282 } 283 }, 284 } 285 } 286 const aa = arena.allocator(); 287 break :blk .{ 288 try Files.emptyResult(aa, location, requested_ref_or_oid orelse .branch, requested_ref_value, files_dir), 289 Changes{ .commits = try Commits.emptyResult(aa, location, requested_ref_or_oid orelse .branch, requested_ref_value, commits_content, commits_base_oid) }, 290 try Refs.emptyResult(arena, repo_identity.identity, refs_kind, refs_from), 291 try Issues.emptyResult(aa, repo_identity.identity, issues_tag, issues_selected, issues_comment, issues_comments_start, issues_theirs, issues_view), 292 try Patches.emptyResult(aa, repo_identity.identity, patches_tag, patches_selected, patches_comment, patches_comments_start, patches_theirs, patches_view), 293 try Discussions.emptyResult(aa, repo_identity.identity, discussions_tag, discussions_selected, discussions_comment, discussions_comments_start, discussions_view), 294 try Events.empty(aa, repo_identity.identity, events_view, session.local != null, session.data.sync_failure), 295 }; 296 }; 297 issues.repo_source = source; 298 patches.repo_source = source; 299 patches.repo_id = repo_id_maybe; 300 discussions.repo_source = source; 301 302 return .{ 303 // use the files tab's resolved ref for the header 304 .header = try Header.init(arena, repo.event.name, owner_name, files.ref_or_oid, files.ref_or_oid_value, issues.tag, patches.tag, discussions.tag), 305 .repo = repo, 306 .files = files, 307 .changes = changes, 308 .refs = refs, 309 .issues = issues, 310 .patches = patches, 311 .discussions = discussions, 312 .events = events, 313 .settings = Settings.init(), 314 .auth = Auth.init(), 315 .quit = Quit.init(), 316 }; 317 } 318 319 pub const View = struct { 320 box: wgt.Box(ui.Widget), 321 322 const header_index: usize = 0; 323 const stack_index: usize = 1; 324 325 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 326 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .rounded_corners = true, .direction = .vert }); 327 errdefer box.deinit(allocator); 328 329 // build the header first so we can grab the files-tab id for the auth 330 // view (it focuses there after login). 331 { 332 var header_view = try Header.View.init(allocator, data, session); 333 errdefer header_view.deinit(allocator); 334 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .repo_header = header_view }, .rect = null, .min_size = null }); 335 } 336 337 { 338 var stack = try wgt.Stack(ui.Widget).init(allocator); 339 errdefer stack.deinit(allocator); 340 341 // files — the default tab: the current directory's listing. 342 { 343 var files_view = try Files.View.init(allocator, &data.files, session); 344 errdefer files_view.deinit(allocator); 345 try stack.children.put(allocator, files_view.getFocus().id, .{ .repo_files = files_view }); 346 } 347 348 switch (data.changes) { 349 .diff => |*diff| { 350 var diff_view = try Diff.View.init(allocator, diff, session); 351 errdefer diff_view.deinit(allocator); 352 try stack.children.put(allocator, diff_view.getFocus().id, .{ .diff_view = diff_view }); 353 }, 354 .commits => |*commits| { 355 var commits_view = try Commits.View.init(allocator, commits, session); 356 errdefer commits_view.deinit(allocator); 357 try stack.children.put(allocator, commits_view.getFocus().id, .{ .repo_commits = commits_view }); 358 }, 359 } 360 361 // refs — the repo's branches and tags. 362 { 363 var refs_view = try Refs.View.init(allocator, &data.refs, session); 364 errdefer refs_view.deinit(allocator); 365 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 366 } 367 368 // issues — the repo's issue tracker and comment permalinks. 369 { 370 var issues_view = try Issues.View.init(allocator, &data.issues, session); 371 errdefer issues_view.deinit(allocator); 372 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 373 } 374 375 // patches and their comment permalinks. 376 { 377 var patches_view = try Patches.View.init(allocator, &data.patches, session); 378 errdefer patches_view.deinit(allocator); 379 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 380 } 381 382 // discussions and their comment permalinks. 383 { 384 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 385 errdefer discussions_view.deinit(allocator); 386 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 387 } 388 389 { 390 var events_view = try Events.View.init(allocator, &data.events, session); 391 errdefer events_view.deinit(allocator); 392 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 393 } 394 395 // the header only shows the settings tab with a login and the auth 396 // tab outside local mode, so keep the stack's children 1:1 with 397 // the tabs by skipping the same views. 398 if (session.data.user_id != null) { 399 var settings_view = try Settings.View.init(allocator, session); 400 errdefer settings_view.deinit(allocator); 401 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 402 } 403 404 if (session.data.host_kind == .server) { 405 var auth_view = try Auth.View.init(allocator, &data.auth, session); 406 errdefer auth_view.deinit(allocator); 407 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 408 } 409 410 if (session.is_terminal) { 411 var quit_view = try Quit.View.init(allocator, session); 412 errdefer quit_view.deinit(allocator); 413 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 414 } 415 416 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 417 } 418 419 var self = View{ .box = box }; 420 // a page opens on its tabs, except that search results open in the 421 // tab's own search box. 422 const results = data.files.find != null or (data.changes == .commits and data.changes.commits.search != null); 423 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 424 return self; 425 } 426 427 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 428 self.box.deinit(allocator); 429 } 430 431 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 432 self.clearGrid(); 433 const header = &self.box.children.values()[header_index].widget.repo_header; 434 const stack = &self.box.children.values()[stack_index].widget.stack; 435 436 // each header tab maps 1:1 to a stack child by position 437 if (header.getSelectedIndex()) |index| 438 stack.getFocus().child_id = stack.children.keys()[index]; 439 try self.box.build(allocator, constraint, root_focus); 440 } 441 442 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 443 const stack = &self.box.children.values()[stack_index].widget.stack; 444 if (self.getFocus().child_id) |child_id| { 445 if (self.box.children.getIndex(child_id)) |current_index| { 446 const child = &self.box.children.values()[current_index].widget; 447 var index = current_index; 448 449 const direction = inp.vertDirection(key); 450 451 switch (direction) { 452 .up => { 453 switch (child.*) { 454 .repo_header => { 455 try child.input(allocator, key, root_focus); 456 }, 457 .stack => { 458 if (child.stack.getSelected()) |selected_widget| { 459 if (selected_widget.atTop(root_focus)) { 460 index = header_index; 461 } else { 462 try child.input(allocator, key, root_focus); 463 } 464 } 465 }, 466 else => {}, 467 } 468 }, 469 .down => { 470 switch (child.*) { 471 .repo_header => { 472 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 473 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 474 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 475 else => {}, 476 }; 477 index = stack_index; 478 }, 479 .stack => { 480 try child.input(allocator, key, root_focus); 481 }, 482 else => {}, 483 } 484 }, 485 .none => { 486 try child.input(allocator, key, root_focus); 487 }, 488 } 489 490 if (index != current_index) { 491 root_focus.setFocus(self.box.children.keys()[index]); 492 } 493 } 494 } 495 } 496 497 pub fn clearGrid(self: *View) void { 498 self.box.clearGrid(); 499 } 500 501 pub fn getGrid(self: View) ?Grid { 502 return self.box.getGrid(); 503 } 504 505 pub fn getFocus(self: *View) *Focus { 506 return self.box.getFocus(); 507 } 508 }; 509