╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
31 user: evt.User.Public, 32 repos: []const evt.Repo.Record, 33 repos_start: usize, // the repos window this page was built with, mirrored into the url 34 repos_next_start: ?usize, // the `start` for the "next" row, or null on the last window 35 repos_search: ?[]const u8, // the name prefix the repos are narrowed to (decoded; null = no search) 36 forks: []const ForkItem, 37 forks_start: usize, 38 forks_next_start: ?usize, 39 settings: Settings, 40 auth: Auth, 41 quit: Quit, 42 43 const Self = @This(); 44 45 pub fn init( 46 arena: *std.heap.ArenaAllocator, 47 session: *ui.Session, 48 haxy_moment: evt.AdminDB.HashMap(.read_only), 49 name: ui.RoutablePage.Array(evt.User.name_max_len), 50 repos_start: usize, 51 // the url-encoded repos search ("" = none) 52 repos_search: []const u8, 53 forks_start: usize, 54 ) !Self { 55 // admin and user repos share one db type 56 const DB = evt.AdminDB; 57 const hash_kind = evt.admin_repo_opts.hash; 58 59 // a route identifies a user by name, which everything below keys off of 60 const user_id = (try evt.User.readIdByName(DB, hash_kind, haxy_moment, name.slice())) orelse return error.NotFound; 61 const user = (try evt.User.readById(DB, hash_kind, haxy_moment, arena, &user_id)) orelse return error.NotFound; 62 63 const io = session.io orelse return error.NoMoment; 64 const users_dir = session.users_dir orelse return error.NoMoment; 65 const gpa = arena.child_allocator; 66 67 // a user with no user repo or no events has empty lists 68 var user_repo_maybe = try evt.openUserRepo(io, gpa, users_dir, &user_id); 69 defer if (user_repo_maybe) |*user_repo| user_repo.deinit(io, gpa); 70 const user_moment = if (user_repo_maybe) |*user_repo| try evt.userMoment(user_repo) else null; 71 72 const search: ?[]const u8 = if (repos_search.len == 0) null else std.Uri.percentDecodeInPlace(try arena.allocator().dupe(u8, repos_search)); 73 74 var repos: std.ArrayList(evt.Repo.Record) = .empty; 75 var repos_next_start: ?usize = null; 76 if (user_moment) |moment| { 77 if (search) |prefix| { 78 if (try moment.getCursor(hash.hashInt(hash_kind, evt.Repo.name_index_key))) |index_cursor| { 79 const index = try DB.SortedMap(.read_only).init(index_cursor); 80 81 // the names with the prefix are contiguous from its rank, so the 82 // window is one seek then a walk that stops at the first name without it 83 var taken: usize = 0; 84 var repos_iter = try index.iteratorFromIndex(try index.rank(prefix) +| repos_start); 85 while (try repos_iter.next()) |cursor| { 86 const pair = try cursor.readKeyValuePair(); 87 const repo_name = try pair.key_cursor.readBytesAlloc(arena.allocator(), null); 88 if (!std.mem.startsWith(u8, repo_name, prefix)) break; 89 if (taken == page_size) { 90 repos_next_start = repos_start + page_size; 91 break; 92 } 93 taken += 1; 94 var event_id: [evt.event_id_size]u8 = undefined; 95 _ = try pair.value_cursor.readBytes(&event_id); 96 const repo_event = (try evt.Repo.readById(DB, hash_kind, moment, arena, &event_id)) orelse continue; 97 // unreadable repos leave their window short rather than shifting the others 98 if (evt.Repo.roleOf(repo_event, session.userId()) == .none) continue; 99 try repos.append(arena.allocator(), repo_event); 100 } 101 } 102 } else { 103 // unsearched, the newest activity comes first. its index sits beside the events. 104 const user_repo = if (user_repo_maybe) |*user_repo| user_repo else unreachable; 105 if (try (try user_repo.core.latestMoment()).getCursor(hash.hashInt(hash_kind, evt.recent_repo_id_set_key))) |recent_cursor| { 106 const recent = try DB.SortedSet(.read_only).init(recent_cursor); 107 const count = try recent.count(); 108 const end = @min(repos_start +| page_size, count); 109 var iter = try recent.iteratorFromIndex(repos_start); 110 var i = repos_start; 111 while (i < end) : (i += 1) { 112 const kv_cursor = (try iter.next()) orelse break; 113 const repo_id = try evt.readOrderKeyId(DB, kv_cursor); 114 const repo_event = (try evt.Repo.readById(DB, hash_kind, moment, arena, &repo_id)) orelse continue; 115 if (evt.Repo.roleOf(repo_event, session.userId()) == .none) continue; 116 try repos.append(arena.allocator(), repo_event); 117 } 118 repos_next_start = if (end < count) end else null; 119 } 120 } 121 } 122 123 var forks: std.ArrayList(ForkItem) = .empty; 124 var forks_next_start: ?usize = null; 125 if (user_moment) |moment| { 126 if (try moment.getCursor(hash.hashInt(hash_kind, evt.Fork.active_id_set_key))) |user_forks_cursor| { 127 const user_forks = try DB.SortedSet(.read_only).init(user_forks_cursor); 128 const count = try user_forks.count(); 129 const end = @min(forks_start +| page_size, count); 130 var iter = try user_forks.iteratorFromIndex(forks_start); 131 var i = forks_start; 132 while (i < end) : (i += 1) { 133 const kv_cursor = (try iter.next()) orelse break; 134 const fork_id = try evt.readOrderKeyId(DB, kv_cursor); 135 const fork_id_hex = std.fmt.bytesToHex(fork_id, .lower); 136 const record = (try evt.Fork.readById(DB, hash_kind, moment, arena, &fork_id)) orelse continue; 137 138 // the target lives in its owner's user repo 139 const owner_id = record.event.repo_user_id[0..evt.event_id_size]; 140 const target_repo = (try evt.readRepoById(io, gpa, arena, users_dir, owner_id, record.event.repo_id)) orelse continue; 141 if (evt.Repo.roleOf(target_repo, session.userId()) == .none) continue; 142 143 var title: []const u8 = "(unavailable)"; 144 const path = try fork.forkPath(arena.allocator(), users_dir, &user_id, &fork_id); 145 if (rp.Repo(.xit, .{}).open(io, gpa, .{ .path = path, .require_repo_root = true })) |opened| { 146 var fork_repo = opened; 147 defer fork_repo.deinit(io, gpa); 148 if (evt.currentMoment(.{}, &fork_repo)) |fork_moment| { 149 if (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, fork_moment, arena, &fork_id)) |patch| title = patch.event.title; 150 } else |_| {} 151 } else |_| {} 152 try forks.append(arena.allocator(), .{ 153 .id = try arena.allocator().dupe(u8, &fork_id_hex), 154 .name = target_repo.event.name, 155 .title = title, 156 }); 157 } 158 forks_next_start = if (end < count) end else null; 159 } 160 } 161 162 return .{ 163 .header = try Header.init(arena, user.event.name), 164 .user = evt.project(evt.User.Public, user.event), 165 .repos = repos.items, 166 .repos_start = repos_start, 167 .repos_next_start = repos_next_start, 168 .repos_search = search, 169 .forks = forks.items, 170 .forks_start = forks_start, 171 .forks_next_start = forks_next_start, 172 .settings = Settings.init(), 173 .auth = Auth.init(), 174 .quit = Quit.init(), 175 }; 176 } 177 178 pub const View = struct { 179 box: wgt.Box(ui.Widget), 180 181 const header_index: usize = 0; 182 const stack_index: usize = 1; 183 184 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 185 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .round_corners = true, .direction = .vert }); 186 errdefer box.deinit(allocator); 187 188 // build the header first so we can grab the repos-tab id for the auth 189 // view (it focuses there after login). 190 { 191 var header_view = try Header.View.init(allocator, &data.header, session); 192 errdefer header_view.deinit(allocator); 193 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .user_header = header_view }, .rect = null, .min_size = null }); 194 } 195 196 { 197 var stack = try wgt.Stack(ui.Widget).init(allocator); 198 errdefer stack.deinit(allocator); 199 200 // repos list — the default tab 201 { 202 var repos_view = try ReposView.init(allocator, data, session); 203 errdefer repos_view.deinit(allocator); 204 try stack.children.put(allocator, repos_view.getFocus().id, .{ .user_repos = repos_view }); 205 } 206 207 // forks list 208 { 209 var list = try ui.widget.FlowBox.Scroll.init(allocator, .{}, !session.is_terminal); 210 errdefer list.deinit(allocator); 211 212 var item_arena = std.heap.ArenaAllocator.init(allocator); 213 defer item_arena.deinit(); 214 const aa = item_arena.allocator(); 215 var items: std.ArrayList(ui.widget.FlowBox.Item) = .empty; 216 if (data.forks_start > 0) 217 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, data.forks_start -| page_size }) }); 218 for (data.forks) |fork_item| { 219 // the fork route names the forker 220 const identity = try std.fmt.allocPrint(aa, "{s}/{s}", .{ data.user.name, fork_item.name }); 221 const route = ui.RoutablePage.forkPatchRoute(identity, fork_item.id) orelse return error.RouteTooLong; 222 try items.append(aa, .{ 223 .text = try std.fmt.allocPrint(aa, "{s} - {s}", .{ fork_item.name, fork_item.title }), 224 .link = try std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}), 225 }); 226 } 227 if (data.forks_next_start) |next_start| 228 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, next_start }) }); 229 try list.setItems(allocator, items.items); 230 try stack.children.put(allocator, list.getFocus().id, .{ .flow_box_scroll = list }); 231 } 232 233 // the header has no settings tab without a login, so keep the 234 // stack's children 1:1 with the tabs by skipping the view too 235 if (session.data.user_id != null) { 236 var settings_view = try Settings.View.init(allocator, session); 237 errdefer settings_view.deinit(allocator); 238 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 239 } 240 241 { 242 var auth_view = try Auth.View.init(allocator, &data.auth, session); 243 errdefer auth_view.deinit(allocator); 244 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 245 } 246 247 if (session.is_terminal) { 248 var quit_view = try Quit.View.init(allocator, session); 249 errdefer quit_view.deinit(allocator); 250 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 251 } 252 253 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 254 } 255 256 var self = View{ .box = box }; 257 // search results open in the tab's own search box 258 self.getFocus().child_id = box.children.keys()[if (data.repos_search != null) stack_index else header_index]; 259 return self; 260 } 261 262 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 263 self.box.deinit(allocator); 264 } 265 266 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 267 self.clearGrid(); 268 const header = &self.box.children.values()[header_index].widget.user_header; 269 const stack = &self.box.children.values()[stack_index].widget.stack; 270 271 // each header tab maps 1:1 to a stack child by position 272 if (header.getSelectedIndex()) |index| 273 stack.getFocus().child_id = stack.children.keys()[index]; 274 try self.box.build(allocator, constraint, root_focus); 275 } 276 277 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 278 const stack = &self.box.children.values()[stack_index].widget.stack; 279 if (self.getFocus().child_id) |child_id| { 280 if (self.box.children.getIndex(child_id)) |current_index| { 281 const child = &self.box.children.values()[current_index].widget; 282 var index = current_index; 283 284 const direction = inp.vertDirection(key); 285 286 switch (direction) { 287 .up => { 288 switch (child.*) { 289 .user_header => { 290 try child.input(allocator, key, root_focus); 291 }, 292 .stack => { 293 if (child.stack.getSelected()) |selected_widget| { 294 if (selected_widget.atTop(root_focus)) { 295 index = header_index; 296 } else { 297 try child.input(allocator, key, root_focus); 298 } 299 } 300 }, 301 else => {}, 302 } 303 }, 304 .down => { 305 switch (child.*) { 306 .user_header => { 307 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 308 .user_repos => |*v| return v.focusHeader(root_focus), 309 // an empty list has nothing to focus 310 .flow_box_scroll => |*v| if (v.isEmpty()) return, 311 else => {}, 312 }; 313 index = stack_index; 314 }, 315 .stack => { 316 try child.input(allocator, key, root_focus); 317 }, 318 else => {}, 319 } 320 }, 321 .none => { 322 try child.input(allocator, key, root_focus); 323 }, 324 } 325 326 if (index != current_index) { 327 root_focus.setFocus(self.box.children.keys()[index]); 328 } 329 } 330 } 331 } 332 333 pub fn clearGrid(self: *View) void { 334 self.box.clearGrid(); 335 } 336 337 pub fn getGrid(self: View) ?Grid { 338 return self.box.getGrid(); 339 } 340 341 pub fn getFocus(self: *View) *Focus { 342 return self.box.getFocus(); 343 } 344 }; 345 346 pub const ReposView = struct { 347 // a vertical box: the search sub-header above the scrolling list. focus 348 // points at the header's box or the list's selected row. 349 box: wgt.Box(ui.Widget), 350 data: *const Self, 351 session: *ui.Session, 352 353 const header_index = 0; 354 const list_index = 1; 355 356 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !ReposView { 357 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 358 errdefer box.deinit(allocator); 359 360 { 361 var header = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 362 errdefer header.deinit(allocator); 363 { 364 var search_box = try ui.widget.SearchBox.init(allocator, session, " search ", "search", data.repos_search); 365 errdefer search_box.deinit(allocator); 366 header.getFocus().child_id = search_box.getFocus().id; 367 try header.children.put(allocator, search_box.getFocus().id, .{ .widget = .{ .search_box = search_box }, .rect = null, .min_size = ui.widget.SearchBox.min_size }); 368 } 369 // the spacer keeps the box at its own width 370 { 371 var spacer = try ui.widget.Spacer.init(allocator); 372 errdefer spacer.deinit(allocator); 373 try header.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 374 } 375 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .box = header }, .rect = null, .min_size = .{ .width = null, .height = ui.widget.SearchBox.min_size.height } }); 376 } 377 378 { 379 var list = try ui.widget.FlowBox.Scroll.init(allocator, .{}, !session.is_terminal); 380 errdefer list.deinit(allocator); 381 382 var arena = std.heap.ArenaAllocator.init(allocator); 383 defer arena.deinit(); 384 const aa = arena.allocator(); 385 386 const route = (reposRoute(data.user.name) orelse return error.RouteTooLong).withSearch(data.repos_search orelse "") orelse return error.RouteTooLong; 387 388 // a leading "previous" row off the first window, one row per repo, 389 // then a trailing "next" row when more remain. each window row 390 // navigates to the adjacent window of this user's repos. 391 var items: std.ArrayList(ui.widget.FlowBox.Item) = .empty; 392 if (data.repos_start > 0) { 393 var prev = route; 394 prev.user_repos.start = data.repos_start -| page_size; 395 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:{s}", .{try prev.toUrl(&arena)}) }); 396 } 397 for (data.repos) |repo| 398 // clicking a repo opens its page; the "a:" prefix makes the web 399 // renderer emit an <a href="/repo/alice/foo"> anchor. 400 try items.append(aa, .{ 401 .text = if (repo.event.description.len == 0) repo.event.name else try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo.event.name, repo.event.description }), 402 .link = try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}", .{ data.user.name, repo.event.name }), 403 }); 404 if (data.repos_next_start) |next_start| { 405 var next = route; 406 next.user_repos.start = next_start; 407 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:{s}", .{try next.toUrl(&arena)}) }); 408 } 409 try list.setItems(allocator, items.items); 410 411 try box.children.put(allocator, list.getFocus().id, .{ .widget = .{ .flow_box_scroll = list }, .rect = null, .min_size = null }); 412 } 413 414 // search results start in the box so the term can be refined right away 415 box.getFocus().child_id = box.children.keys()[if (data.repos_search != null) header_index else list_index]; 416 return .{ .box = box, .data = data, .session = session }; 417 } 418 419 pub fn deinit(self: *ReposView, allocator: std.mem.Allocator) void { 420 self.box.deinit(allocator); 421 } 422 423 pub fn build(self: *ReposView, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 424 self.clearGrid(); 425 // clear the incoming min height so the list scrolls within what's left 426 try self.box.build(allocator, .{ 427 .min_size = .{ .width = null, .height = null }, 428 .max_size = constraint.max_size, 429 }, root_focus); 430 } 431 432 pub fn input(self: *ReposView, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 433 const direction = inp.vertDirection(key); 434 if (self.headerActive()) { 435 const search_box = self.searchBox(); 436 if (direction == .down) return root_focus.setFocus(self.listScroll().getFocus().id); 437 if (key == .enter) { 438 const text = try search_box.text(allocator); 439 defer allocator.free(text); 440 return self.submit(text); 441 } 442 return search_box.input(allocator, key, root_focus); 443 } 444 // up from the first row reaches the search box 445 if (direction == .up and self.listScroll().atTop()) return self.focusHeader(root_focus); 446 try self.listScroll().input(allocator, key, root_focus); 447 } 448 449 // the repos narrowed to `text` from the first window. an empty box on an 450 // unsearched page has nothing to clear. 451 fn submit(self: *ReposView, text: []const u8) !void { 452 if (text.len == 0 and self.data.repos_search == null) return; 453 const route = reposRoute(self.data.user.name) orelse return; 454 try self.session.navigate(route.withSearch(text) orelse return); 455 } 456 457 fn searchBox(self: *ReposView) *ui.widget.SearchBox { 458 return &self.box.children.values()[header_index].widget.box.children.values()[0].widget.search_box; 459 } 460 461 fn listScroll(self: *ReposView) *ui.widget.FlowBox.Scroll { 462 return &self.box.children.values()[list_index].widget.flow_box_scroll; 463 } 464 465 fn headerActive(self: *ReposView) bool { 466 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 467 } 468 469 pub fn clearGrid(self: *ReposView) void { 470 self.box.clearGrid(); 471 } 472 473 pub fn getGrid(self: ReposView) ?Grid { 474 return self.box.getGrid(); 475 } 476 477 pub fn getFocus(self: *ReposView) *Focus { 478 return self.box.getFocus(); 479 } 480 481 // up leaves the tab from the search box 482 pub fn atTop(self: *ReposView) bool { 483 return self.headerActive(); 484 } 485 486 pub fn focusHeader(self: *ReposView, root_focus: *Focus) void { 487 root_focus.setFocus(self.searchBox().getFocus().id); 488 } 489 }; 490 491 // the first window of `name`'s repos 492 fn reposRoute(name: []const u8) ?ui.RoutablePage { 493 return .{ .user_repos = .{ .name = ui.RoutablePage.Array(evt.User.name_max_len).from(name) orelse return null } }; 494 } 495