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