╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../../event.zig"); 3 const ui = @import("../../ui.zig"); 4 const xit = @import("xit"); 5 const rp = xit.repo; 6 const tr = xit.tree; 7 const df = xit.diff; 8 const xitui = xit.xitui; 9 const wgt = xitui.widget; 10 const layout = xitui.layout; 11 const Key = xitui.input.Key; 12 const Grid = xitui.grid.Grid; 13 const Focus = xitui.focus.Focus; 14 const inp = @import("../input.zig"); 15 16 // how many lines of a file's content one window shows before a "next" link. 17 const file_page = 5000; 18 19 // how many files in a directory get their content preloaded (windowed) so 20 // selecting them shows contents without a reload. every entry is still listed; 21 // files past this limit carry an "a:" link instead, so activating them reloads 22 // the page with that file selected (and its content loaded as the selection). 23 const max_preloaded = 100; 24 25 // one entry in the directory currently being viewed. 26 pub const Entry = struct { 27 name: []const u8, 28 is_dir: bool, 29 // a file's content window split into lines (each without its trailing 30 // newline); empty for directories and for binary or empty files. 31 lines: []const []const u8 = &.{}, 32 // true when xit's line iterator flagged the file as binary, so the detail 33 // pane shows a placeholder rather than its bytes. 34 is_binary: bool = false, 35 // the line index this window starts at (0 = the first window). non-zero only 36 // for the route's selected file, paginated by the url's `line`. 37 window_start: usize = 0, 38 // whether more lines exist after this window. 39 has_more: bool = false, 40 // whether this file's content was read; unloaded files load via their 41 // "a:" link. 42 loaded: bool = false, 43 }; 44 45 // "owner/name", so the view can build /repo/owner/name/files/... links. 46 identity: []const u8, 47 // the resolved ref this listing is read at (the default branch when the route 48 // didn't name one), so the view's directory links stay pinned to it. 49 ref_or_oid: ui.RoutablePage.RefOrOid, 50 ref_or_oid_value: []const u8, 51 // the directory being viewed, relative to the repo root ("" at the root). 52 dir: []const u8, 53 // a file within `dir` to start selected (so its contents show and the url 54 // carries it), or null to fall back to a README / the first row. set when the 55 // route's path named a file rather than a directory. 56 selected_file: ?[]const u8 = null, 57 entries: []const Entry, 58 // the "viewing <ref> <value>" banner shown above the listing. 59 header: Header, 60 61 const Self = @This(); 62 63 // build the listing for an opened repo. generic over the repo's backend and 64 // hash kind so the tree/diff types it threads through match the repo's opts. 65 // reads with the arena's backing allocator (transient); the listing is built 66 // into the page arena so it outlives the repo handle. 67 pub fn init( 68 comptime repo_kind: rp.RepoKind, 69 comptime repo_opts: rp.RepoOpts(repo_kind), 70 arena: *std.heap.ArenaAllocator, 71 repo: *rp.Repo(repo_kind, repo_opts), 72 io: std.Io, 73 gpa: std.mem.Allocator, 74 identity: []const u8, 75 requested_ref_or_oid: ?ui.RoutablePage.RefOrOid, 76 requested_value: []const u8, 77 path: []const u8, 78 line: usize, 79 ) !Self { 80 const aa = arena.allocator(); 81 82 // resolve the requested ref (or the default branch) to the commit oid whose 83 // tree we list. a ref the route named explicitly that doesn't resolve is a 84 // bad url (NotFound -> 404); the default-branch path falls through to empty. 85 const resolved = (try ui.ResolvedRefOrOid(repo_kind, repo_opts).init(repo, io, aa, requested_ref_or_oid, requested_value)) orelse { 86 if (requested_ref_or_oid != null) return error.NotFound; 87 return emptyResult(aa, identity, .branch, requested_value, path); 88 }; 89 90 // read just the viewed directory of that commit's tree. building the 91 // read-only state mirrors what repo.status does internally, but for an 92 // arbitrary commit rather than HEAD. a path that doesn't exist in the tree 93 // is a bad url (404). 94 var moment = repo.core.latestMoment() catch return emptyResult(aa, identity, resolved.ref_or_oid, resolved.value, path); 95 const state = rp.Repo(repo_kind, repo_opts).State(.read_only){ .core = &repo.core, .extra = .{ .moment = &moment } }; 96 var tree_dir = tr.TreeDir(repo_kind, repo_opts).init(state, io, gpa, &resolved.oid, path) catch |err| switch (err) { 97 error.TreeEntryNotFound => return error.NotFound, 98 else => return emptyResult(aa, identity, resolved.ref_or_oid, resolved.value, path), 99 }; 100 defer tree_dir.deinit(); 101 102 // when `path` named a file, the listing is its parent directory with that 103 // file selected. 104 var dir = path; 105 var selected_file: ?[]const u8 = null; 106 if (tree_dir.file_name != null) { 107 const slash = std.mem.lastIndexOfScalar(u8, path, '/'); 108 selected_file = try aa.dupe(u8, if (slash) |s| path[s + 1 ..] else path); 109 dir = if (slash) |s| path[0..s] else ""; 110 } 111 112 // tree objects store their entries in name order, so the listing is 113 // already sorted. group directories before files, keeping that order 114 // within each group, and dupe into the page arena. file contents are read 115 // here (into the page arena) so the detail pane can show them without 116 // another lookup. 117 const entries = try aa.alloc(Entry, tree_dir.entries.count()); 118 var i: usize = 0; 119 var preloaded: usize = 0; 120 for ([_]bool{ true, false }) |want_dir| { 121 for (tree_dir.entries.keys(), tree_dir.entries.values()) |name, tree_entry| { 122 if (tree_entry.isTree() != want_dir) continue; 123 var entry: Entry = .{ .name = try aa.dupe(u8, name), .is_dir = want_dir }; 124 if (!want_dir) { 125 // only the route's selected file paginates; the rest show 126 // their first window (for the in-page detail when selected). 127 const is_selected = if (selected_file) |sf| std.mem.eql(u8, sf, name) else false; 128 // the README always loads because it's the default selection. 129 if (preloaded < max_preloaded or is_selected or isReadme(name)) { 130 preloaded += 1; 131 const file_path = try childDir(aa, dir, name); 132 // the url's `line` is 1-based (0 = unset); the window 133 // index is 0-based. 134 const window_start = if (is_selected) line -| 1 else 0; 135 const content = readFileContent(repo_kind, repo_opts, state, io, gpa, aa, file_path, tree_entry, window_start) catch 136 FileContent{ .lines = &.{} }; 137 entry.lines = content.lines; 138 entry.is_binary = content.is_binary; 139 entry.window_start = window_start; 140 entry.has_more = content.has_more; 141 entry.loaded = true; 142 } 143 } 144 entries[i] = entry; 145 i += 1; 146 } 147 } 148 149 return .{ 150 .identity = try aa.dupe(u8, identity), 151 .ref_or_oid = resolved.ref_or_oid, 152 .ref_or_oid_value = resolved.value, 153 .dir = try aa.dupe(u8, dir), 154 .selected_file = selected_file, 155 .entries = entries, 156 .header = try Header.init(aa, resolved.ref_or_oid, resolved.value), 157 }; 158 } 159 160 const FileContent = struct { 161 lines: []const []const u8, 162 is_binary: bool = false, 163 has_more: bool = false, 164 }; 165 166 // read the window [start, start+file_page) of a committed file's contents at 167 // `tree_entry` into `arena`-owned lines, flagging whether more follow. xit's 168 // line iterator flags binary files (its source becomes `.binary`), in which case 169 // we report no lines and let the view show a placeholder. 170 fn readFileContent( 171 comptime repo_kind: rp.RepoKind, 172 comptime repo_opts: rp.RepoOpts(repo_kind), 173 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 174 io: std.Io, 175 gpa: std.mem.Allocator, 176 arena: std.mem.Allocator, 177 path: []const u8, 178 tree_entry: tr.TreeEntry(repo_opts.hash), 179 start: usize, 180 ) !FileContent { 181 var line_iter = try df.LineIterator(repo_kind, repo_opts).initFromTree(state, io, gpa, path, tree_entry); 182 defer line_iter.deinit(); 183 if (line_iter.source == .binary) return .{ .lines = &.{}, .is_binary = true }; 184 185 // init reads through the file to validate it (and buffer it in memory), so 186 // the line count is known and a window can be sliced out of the buffer. 187 const total = line_iter.count(); 188 const end = @min(start + file_page, total); 189 190 var lines: std.ArrayList([]const u8) = .empty; 191 var i = start; 192 while (i < end) : (i += 1) { 193 const line = try line_iter.get(i); 194 defer line_iter.free(line); 195 try lines.append(arena, try arena.dupe(u8, line)); 196 } 197 return .{ 198 .lines = try lines.toOwnedSlice(arena), 199 .has_more = end < total, 200 }; 201 } 202 203 // an empty listing pinned to a ref, for the wasm / no-repo / unresolved paths. 204 pub fn emptyResult(aa: std.mem.Allocator, identity: []const u8, ref_or_oid: ui.RoutablePage.RefOrOid, ref_or_oid_value: []const u8, dir: []const u8) !Self { 205 return .{ 206 .identity = try aa.dupe(u8, identity), 207 .ref_or_oid = ref_or_oid, 208 .ref_or_oid_value = try aa.dupe(u8, ref_or_oid_value), 209 .dir = try aa.dupe(u8, dir), 210 .entries = &.{}, 211 .header = try Header.init(aa, ref_or_oid, ref_or_oid_value), 212 }; 213 } 214 215 pub const View = struct { 216 // a vertical stack: the "viewing <ref>" banner on top, then a horizontal 217 // split with the file/directory list on the left and a detail pane on the 218 // right showing the selected file's contents. 219 box: wgt.Box(ui.Widget), // vert: [header_index] = banner, [content_index] = split 220 data: *const Self, 221 session: *ui.Session, 222 // the list row whose contents the detail pane currently shows. 223 shown_index: ?usize, 224 225 const header_index: usize = 0; 226 const content_index: usize = 1; 227 // indices within the content box (the horizontal split). 228 const list_index: usize = 0; 229 const detail_index: usize = 1; 230 // indices within the detail pane frame (nav box above the content scroll). 231 const detail_nav_index: usize = 0; 232 const detail_scroll_index: usize = 1; 233 const list_max_width: usize = 40; 234 const detail_min_width: usize = 40; 235 // a list row's height: one text line inside its (hidden) border. 236 const row_height: usize = 3; 237 238 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 239 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 240 errdefer outer.deinit(allocator); 241 242 // the ref banner at the top. 243 { 244 var header = try Header.View.init(allocator, &data.header, session); 245 errdefer header.deinit(allocator); 246 try outer.children.put(allocator, header.getFocus().id, .{ .widget = .{ .repo_files_header = header }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 247 } 248 249 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 250 errdefer box.deinit(allocator); 251 252 // the directory listing on the left (one focusable row each). 253 { 254 var list_scroll = blk: { 255 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 256 errdefer list_box.deinit(allocator); 257 258 // labels and link kinds are borrowed by the rows, so they live in 259 // the page arena (as long as this page's widget tree). 260 const aa = session.page_arena.allocator(); 261 if (data.dir.len != 0) { 262 try addRow(allocator, &list_box, "..", try dirLink(session.page_arena, data, parentDir(data.dir))); 263 } 264 for (data.entries) |entry| { 265 const path = try childDir(aa, data.dir, entry.name); 266 const label = if (entry.is_dir) try std.fmt.allocPrint(aa, "{s}/", .{entry.name}) else entry.name; 267 const link = if (entry.is_dir) 268 try dirLink(session.page_arena, data, path) 269 else 270 try fileLink(session.page_arena, data, path, entry.loaded); 271 try addRow(allocator, &list_box, label, link); 272 } 273 // select the file the route named, else prefer a README so its 274 // contents greet the visitor in the detail pane, else the first 275 // row. a non-root directory has a leading ".." row, so the entry 276 // index is offset by one there. 277 var sel: usize = 0; 278 if (list_box.children.count() > 0) { 279 const base: usize = if (data.dir.len != 0) 1 else 0; 280 const entry_idx = selectedFileIndex(data) orelse readmeIndex(data.entries); 281 sel = if (entry_idx) |i| i + base else 0; 282 list_box.getFocus().child_id = list_box.children.keys()[sel]; 283 } 284 var sc = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 285 // start scrolled so the selected row begins at the top of the 286 // viewport. rows are a fixed height, so no layout pass is 287 // needed; a too-far offset near the end of the list is clamped 288 // in build (the browser clamps its own scrolling natively). 289 sc.y = @intCast(sel * row_height); 290 break :blk sc; 291 }; 292 errdefer list_scroll.deinit(allocator); 293 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 294 } 295 296 // the detail pane on the right — a "next" nav box above a scroll of the 297 // selected file's content window. both are repopulated per selection by 298 // populateDetail. 299 { 300 var detail_outer = blk: { 301 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 302 errdefer frame.deinit(allocator); 303 304 { 305 var nav_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 306 errdefer nav_box.deinit(allocator); 307 try frame.children.put(allocator, nav_box.getFocus().id, .{ .widget = .{ .box = nav_box }, .rect = null, .min_size = null }); 308 } 309 { 310 // the content scroll wrapped in a bordered box; build sets the 311 // border single normally and double when the content is focused 312 // (the content box itself is borderless). 313 var scroll_frame = blk2: { 314 var detail_scroll = blk3: { 315 var detail_inner = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 316 errdefer detail_inner.deinit(allocator); 317 break :blk3 try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_inner }, .{ .direction = .both, .web_native = !session.is_terminal, .fill = true }); 318 }; 319 errdefer detail_scroll.deinit(allocator); 320 var sf = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .single, .rounded_corners = true, .direction = .vert }); 321 errdefer sf.deinit(allocator); 322 // the wrapper's selected child is its scroll, so the focus 323 // chain reaches the content box (populateDetail points the 324 // scroll's inner box at it). 325 sf.getFocus().child_id = detail_scroll.getFocus().id; 326 try sf.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = null }); 327 break :blk2 sf; 328 }; 329 errdefer scroll_frame.deinit(allocator); 330 // entering the detail pane lands on the content scroll (focus 331 // recovery descends the frame's selected child). the nav links 332 // above are reached by scrolling to the top, then up. 333 frame.getFocus().child_id = scroll_frame.getFocus().id; 334 // shrink, so the fill scroll yields the nav box's row 335 // instead of consuming the frame's whole height. 336 try frame.children.put(allocator, scroll_frame.getFocus().id, .{ .widget = .{ .box = scroll_frame }, .rect = null, .min_size = null, .shrink = true }); 337 } 338 break :blk frame; 339 }; 340 errdefer detail_outer.deinit(allocator); 341 try box.children.put(allocator, detail_outer.getFocus().id, .{ .widget = .{ .box = detail_outer }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 342 } 343 344 box.getFocus().child_id = box.children.keys()[list_index]; 345 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 346 347 // focus lives in the split; the banner isn't focusable. 348 outer.getFocus().child_id = outer.children.keys()[content_index]; 349 return .{ .box = outer, .data = data, .session = session, .shown_index = null }; 350 } 351 352 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 353 var row = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 354 errdefer row.deinit(allocator); 355 row.getFocus().focusable = true; 356 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 357 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null }); 358 } 359 360 // the selected file's contents as a single focusable multi-line text box. 361 // it's borderless — the border lives on the surrounding scroll frame, which 362 // doubles when this content is focused. `text` lives in the page arena. a 363 // non-empty `link` makes activating the box follow it, like addRow. 364 fn addContentBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), text: []const u8, link: []const u8) !void { 365 _ = self; 366 var tb = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = null, .wrap_kind = .none }); 367 errdefer tb.deinit(allocator); 368 tb.getFocus().focusable = true; 369 if (link.len != 0) tb.getFocus().kind = .{ .custom = link }; 370 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 371 } 372 373 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 374 self.box.deinit(allocator); 375 } 376 377 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 378 return &self.box.children.values()[content_index].widget.box; 379 } 380 381 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 382 return &self.contentBox().children.values()[list_index].widget.scroll; 383 } 384 385 fn listBox(self: *View) *wgt.Box(ui.Widget) { 386 return &self.listScroll().child.box; 387 } 388 389 fn detailOuter(self: *View) *wgt.Box(ui.Widget) { 390 return &self.contentBox().children.values()[detail_index].widget.box; 391 } 392 393 fn navBox(self: *View) *wgt.Box(ui.Widget) { 394 return &self.detailOuter().children.values()[detail_nav_index].widget.box; 395 } 396 397 // the bordered box wrapping the content scroll (border toggles with focus). 398 fn detailScrollFrame(self: *View) *wgt.Box(ui.Widget) { 399 return &self.detailOuter().children.values()[detail_scroll_index].widget.box; 400 } 401 402 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 403 return &self.detailScrollFrame().children.values()[0].widget.scroll; 404 } 405 406 fn detailInner(self: *View) *wgt.Box(ui.Widget) { 407 return &self.detailScroll().child.box; 408 } 409 410 fn detailActive(self: *View) bool { 411 const content = self.contentBox(); 412 const cid = content.getFocus().child_id orelse return false; 413 return content.children.getIndex(cid) == detail_index; 414 } 415 416 // the selected list row's index, or null when nothing is focused. 417 fn selectedRowIndex(self: *View) ?usize { 418 const lb = self.listBox(); 419 const cid = lb.getFocus().child_id orelse return null; 420 return lb.children.getIndex(cid); 421 } 422 423 // the entry the selected row points at, or null for the ".." row (which 424 // isn't an entry). directory rows return their entry too, though they carry 425 // no contents. 426 fn selectedEntry(self: *View) ?Entry { 427 const idx = self.selectedRowIndex() orelse return null; 428 const base: usize = if (self.data.dir.len != 0) 1 else 0; // skip the ".." row 429 if (idx < base) return null; 430 const e = idx - base; 431 if (e >= self.data.entries.len) return null; 432 return self.data.entries[e]; 433 } 434 435 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 436 self.clearGrid(); 437 438 // swap the detail pane to the selected entry when the selection changes. 439 try self.refreshDetail(allocator); 440 441 // mirror the selected file into the url so it updates as the selection 442 // moves, but only while focus is inside this view (so landing on the tab 443 // keeps the page's base route). 444 if (root_focus.grandchild_id) |g| { 445 if (self.box.getFocus().children.contains(g)) { 446 var buf: [ui.RoutablePage.repo_route_max_len]u8 = undefined; 447 var sel_path = self.data.dir; 448 var sel_line: usize = 0; 449 if (self.selectedEntry()) |entry| { 450 if (!entry.is_dir and entry.loaded) { 451 sel_path = if (self.data.dir.len == 0) 452 entry.name 453 else 454 std.fmt.bufPrint(&buf, "{s}/{s}", .{ self.data.dir, entry.name }) catch self.data.dir; 455 sel_line = lineNumber(entry.window_start); 456 } 457 } 458 if (ui.RoutablePage.repoFilesRoute(self.data.identity, self.data.ref_or_oid, self.data.ref_or_oid_value, sel_path, sel_line)) |route| 459 self.session.data.current_page = route; 460 } 461 } 462 463 // the selected list row shows a border (the focused TextBox upgrades it 464 // to a double border itself); the rest stay borderless. 465 const lb = self.listBox(); 466 for (lb.children.keys(), lb.children.values()) |id, *child| { 467 switch (child.widget) { 468 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 469 else => {}, 470 } 471 } 472 473 // the content scroll's border is single normally and double when the 474 // content is focused (the content box itself is borderless). 475 const has_content = self.detailInner().children.count() > 0; 476 const content_focused = if (root_focus.grandchild_id) |g| self.detailInner().children.contains(g) else false; 477 self.detailScrollFrame().options.border_style = if (!has_content) null else if (content_focused) .double else .single; 478 479 // cap the list at list_max_width only while the detail pane fits beside 480 // it. the box drops the detail pane when the width can't hold both 481 // minimums, so when it's that narrow we lift the cap and let the list 482 // fill the whole width. 483 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 484 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 485 486 // stretch the detail pane and its bordered scroll frame across the rest 487 // of the width so the pane fills the area rather than shrinking to its 488 // content, like the refs view's columns. the content scroll inside keeps 489 // its natural width: forcing it to the full inner width would make it one 490 // column too wide whenever the vertical scrollbar appears, leaving a 491 // phantom horizontal scroll. (height fills via the scroll clipping to the 492 // viewport.) 493 if (constraint.max_size.width) |w| { 494 const detail_w = if (both_panes_fit) w - list_max_width else w; 495 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_w, .height = null }; 496 self.detailOuter().children.values()[detail_scroll_index].min_size = .{ .width = detail_w, .height = null }; 497 } else { 498 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 499 self.detailOuter().children.values()[detail_scroll_index].min_size = null; 500 } 501 502 // crossing panes only re-selects the content box's child (focusList / 503 // focusDetail); when the window is too narrow to show both, the pane that 504 // was holding focus is dropped here. the framework recovers focus after 505 // the top-level build by re-deriving it down the selected-child chain, so 506 // there's nothing to fix up afterward. 507 try self.box.build(allocator, constraint, root_focus); 508 509 // clamp the list's initial offset (a selected row near the end of the 510 // list) against this build's grids, for the next frame. initRoot's 511 // pre-sizing build is unbounded — its full-content "viewport" would 512 // clamp the offset to zero, so only a bounded build counts. 513 if (constraint.max_size.height != null) self.listScroll().clampToContent(); 514 } 515 516 fn refreshDetail(self: *View, allocator: std.mem.Allocator) !void { 517 const cur = self.selectedRowIndex(); 518 if (std.meta.eql(cur, self.shown_index)) return; 519 try self.populateDetail(allocator); 520 self.shown_index = cur; 521 } 522 523 fn populateDetail(self: *View, allocator: std.mem.Allocator) !void { 524 const nav_box = self.navBox(); 525 const inner = self.detailInner(); 526 527 for (nav_box.children.values()) |*child| child.widget.deinit(allocator); 528 nav_box.children.clearAndFree(allocator); 529 nav_box.getFocus().child_id = null; 530 for (inner.children.values()) |*child| child.widget.deinit(allocator); 531 inner.children.clearAndFree(allocator); 532 inner.getFocus().child_id = null; 533 534 // only files have contents to show; directories and the ".." row leave 535 // the pane empty. 536 if (self.selectedEntry()) |entry| { 537 if (!entry.is_dir) { 538 // the window links sit above the scroll, so they stay put 539 // while the content scrolls. 540 if (entry.window_start > 0) try self.addNavLink(allocator, nav_box, "scroll to top", entry, 0); 541 if (entry.has_more) try self.addNavLink(allocator, nav_box, "next lines →", entry, lineNumber(entry.window_start + file_page)); 542 if (!entry.loaded) { 543 // the placeholder carries the file's "a:" link, so enter 544 // (or a click) here loads the file like on its list row. 545 const path = try childDir(self.session.page_arena.allocator(), self.data.dir, entry.name); 546 const link = try fileLink(self.session.page_arena, self.data, path, false); 547 try self.addContentBox(allocator, inner, "(press enter to load this file)", link); 548 } else if (entry.is_binary) { 549 try self.addContentBox(allocator, inner, "(binary file)", ""); 550 } else { 551 const text = try numberedContent(self.session.page_arena.allocator(), entry.lines, entry.window_start); 552 try self.addContentBox(allocator, inner, text, ""); 553 } 554 } 555 } 556 // point each box at its first child so focus can descend into it. 557 if (nav_box.children.count() > 0) nav_box.getFocus().child_id = nav_box.children.keys()[0]; 558 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 559 560 // reserve the nav row's height (the shrink scroll frame yields it). 561 self.detailOuter().children.values()[detail_nav_index].min_size = 562 if (nav_box.children.count() > 0) .{ .width = null, .height = row_height } else null; 563 564 // reset the scroll to the top for the newly-shown file: directly on the 565 // terminal (the wasm offset), and via a version bump on the web (so the 566 // renderer's scroll id changes and JS drops the preserved position). 567 const sc = self.detailScroll(); 568 sc.x = 0; 569 sc.y = 0; 570 sc.getFocus().version +%= 1; 571 } 572 573 // a focusable "next" link above the content. it's an `a:` link to the 574 // selected file at `target_start`, so activating it (the host follows the 575 // link) reloads the page on the next window. 576 fn addNavLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, entry: Entry, target_start: usize) !void { 577 const page_arena = self.session.page_arena; 578 const path = try childDir(page_arena.allocator(), self.data.dir, entry.name); 579 const route = ui.RoutablePage.repoFilesRoute(self.data.identity, self.data.ref_or_oid, self.data.ref_or_oid_value, path, target_start) orelse return error.RouteTooLong; 580 const link = try std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.toUrl(page_arena)}); 581 var tb = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 582 errdefer tb.deinit(allocator); 583 tb.getFocus().focusable = true; 584 tb.getFocus().kind = .{ .custom = link }; 585 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 586 } 587 588 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 589 _ = allocator; 590 if (self.detailActive()) { 591 try self.detailInput(key, root_focus); 592 } else { 593 try self.listInput(key, root_focus); 594 } 595 } 596 597 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 598 // up/down (and the scroll wheel) move the selection; page up/down jump a 599 // fixed amount. right/Enter cross into the detail pane. Enter/clicks on a 600 // directory (or "..") row are turned into navigation by the host 601 // (crossPageLink) before reaching here. 602 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 603 ui.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 604 return; 605 } 606 switch (key) { 607 .enter, .arrow_right => try self.focusDetail(root_focus), 608 else => {}, 609 } 610 } 611 612 // whether focus is on the content box (vs. a "previous"/"next" nav link). 613 fn focusOnContent(self: *View, root_focus: *Focus) bool { 614 const g = root_focus.grandchild_id orelse return false; 615 return self.detailInner().children.contains(g); 616 } 617 618 fn detailInput(self: *View, key: Key, root_focus: *Focus) !void { 619 const sc = self.detailScroll(); 620 const on_content = self.focusOnContent(root_focus); 621 // the "next" link sits above the content scroll. on the link, left returns 622 // to the file list and down drops into the content. in the content, the 623 // terminal scrolls by offset and reaching the top then pressing up crosses 624 // back up to the link; on the web vertical scrolling is the browser's job 625 // so up just crosses to the link. 626 switch (key) { 627 .arrow_left => { 628 if (on_content) { 629 if (sc.x > 0) { 630 sc.x -= 1; 631 self.detailScroll().clampToContent(); 632 } else try self.focusList(root_focus); 633 } else if (!self.moveNav(root_focus, -1)) { 634 try self.focusList(root_focus); 635 } 636 }, 637 .arrow_right => { 638 if (on_content) { 639 sc.x += 1; 640 self.detailScroll().clampToContent(); 641 } else _ = self.moveNav(root_focus, 1); 642 }, 643 .arrow_up => { 644 if (on_content) { 645 if (self.session.is_terminal and sc.y > 0) { 646 sc.y -= 1; 647 self.detailScroll().clampToContent(); 648 } else self.focusNav(root_focus); // cross up to the links 649 } 650 }, 651 .arrow_down => { 652 if (on_content) { 653 if (self.session.is_terminal) { 654 sc.y += 1; 655 self.detailScroll().clampToContent(); 656 } 657 } else self.focusContent(root_focus); // links -> content 658 }, 659 .page_up => if (on_content and self.session.is_terminal) { 660 sc.y -= 10; 661 self.detailScroll().clampToContent(); 662 }, 663 .page_down => if (on_content and self.session.is_terminal) { 664 sc.y += 10; 665 self.detailScroll().clampToContent(); 666 }, 667 .home => if (on_content and self.session.is_terminal) { 668 sc.y = 0; 669 self.detailScroll().clampToContent(); 670 }, 671 .end => if (on_content and self.session.is_terminal) { 672 sc.y = std.math.maxInt(isize); 673 self.detailScroll().clampToContent(); 674 }, 675 .mouse => |mouse| switch (mouse.action) { 676 .scroll => |dir| if (on_content and self.session.is_terminal) { 677 sc.y += if (dir == .up) -5 else 5; 678 self.detailScroll().clampToContent(); 679 }, 680 else => {}, 681 }, 682 else => {}, 683 } 684 } 685 686 // focus the first (left-most) nav link; a no-op when there are none, leaving 687 // focus on the content. 688 fn focusNav(self: *View, root_focus: *Focus) void { 689 const nav_box = self.navBox(); 690 if (nav_box.children.count() == 0) return; 691 root_focus.setFocus(nav_box.children.keys()[0]); 692 } 693 694 fn focusContent(self: *View, root_focus: *Focus) void { 695 const inner = self.detailInner(); 696 const id = inner.getFocus().child_id orelse (if (inner.children.count() > 0) inner.children.keys()[0] else return); 697 root_focus.setFocus(id); 698 } 699 700 // move focus `delta` rows within the nav box; returns false (without moving) 701 // when that would step off either end. 702 fn moveNav(self: *View, root_focus: *Focus, delta: isize) bool { 703 const nav_box = self.navBox(); 704 const keys = nav_box.children.keys(); 705 const cur_id = nav_box.getFocus().child_id orelse return false; 706 const cur: isize = @intCast(nav_box.children.getIndex(cur_id) orelse return false); 707 const target = cur + delta; 708 if (target < 0 or target >= @as(isize, @intCast(keys.len))) return false; 709 root_focus.setFocus(keys[@intCast(target)]); 710 return true; 711 } 712 713 // enter the detail pane, landing on the "next" link when there is one (so 714 // right-arrow reaches it), else on the content. a directory or ".." row has 715 // neither, so there's nothing to enter. selecting the frame's child (then 716 // focusing the frame) also handles the too-narrow case where the pane isn't 717 // laid out yet — focus lands inside it after the next build. 718 fn focusDetail(self: *View, root_focus: *Focus) !void { 719 const frame = self.detailOuter(); 720 if (self.navBox().children.count() > 0) { 721 frame.getFocus().child_id = self.navBox().getFocus().id; 722 } else if (self.detailInner().children.count() > 0) { 723 frame.getFocus().child_id = self.detailScrollFrame().getFocus().id; 724 } else return; 725 root_focus.setFocus(frame.getFocus().id); 726 } 727 728 // return to the list. 729 fn focusList(self: *View, root_focus: *Focus) !void { 730 root_focus.setFocus(self.listScroll().getFocus().id); 731 } 732 733 pub fn clearGrid(self: *View) void { 734 self.box.clearGrid(); 735 } 736 737 pub fn getGrid(self: View) ?Grid { 738 return self.box.getGrid(); 739 } 740 741 pub fn getFocus(self: *View) *Focus { 742 return self.box.getFocus(); 743 } 744 745 // for the parent's "scroll up at the top jumps to the header" check. inside 746 // the detail pane up-arrow stays in the pane (scrolling); when the list holds 747 // focus, report its selection directly so up-arrow at the top row ascends. 748 pub fn getSelectedIndex(self: *View) ?usize { 749 if (self.detailActive()) return 1; 750 const lb = self.listBox(); 751 const cid = lb.getFocus().child_id orelse return null; 752 return lb.children.getIndex(cid); 753 } 754 }; 755 756 // join `lines` into one string, each prefixed with its 1-based file line number 757 // (right-aligned in a column wide enough for the last number, then a space), 758 // like the diffs view. `start` is the window's 0-based first line, so numbers 759 // continue across paginated windows. 760 fn numberedContent(arena: std.mem.Allocator, lines: []const []const u8, start: usize) ![]const u8 { 761 if (lines.len == 0) return ""; 762 const width = std.fmt.count("{d}", .{start + lines.len}); 763 const indent = try arena.alloc(u8, width); 764 @memset(indent, ' '); 765 766 var out: std.ArrayList(u8) = .empty; 767 for (lines, 0..) |line, i| { 768 if (i != 0) try out.append(arena, '\n'); 769 const num_str = try std.fmt.allocPrint(arena, "{d}", .{start + i + 1}); 770 try out.appendSlice(arena, indent[0 .. width - num_str.len]); 771 try out.appendSlice(arena, num_str); 772 try out.append(arena, ' '); 773 try out.appendSlice(arena, line); 774 } 775 return out.toOwnedSlice(arena); 776 } 777 778 // the index of the "README"/"README.md" file entry (case-insensitive), or null 779 // if none. used to pick the default selection at the repo root. 780 fn readmeIndex(entries: []const Entry) ?usize { 781 for (entries, 0..) |entry, i| { 782 if (!entry.is_dir and isReadme(entry.name)) return i; 783 } 784 return null; 785 } 786 787 fn isReadme(name: []const u8) bool { 788 return std.ascii.eqlIgnoreCase(name, "README") or std.ascii.eqlIgnoreCase(name, "README.md"); 789 } 790 791 // the index of the entry the route named (data.selected_file), or null if none. 792 fn selectedFileIndex(data: *const Self) ?usize { 793 const name = data.selected_file orelse return null; 794 for (data.entries, 0..) |entry, i| { 795 if (!entry.is_dir and std.mem.eql(u8, entry.name, name)) return i; 796 } 797 return null; 798 } 799 800 // an "a:" link to the files route at `path`, pinned to the listing's ref, so 801 // following it navigates to that directory's listing. 802 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 803 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 804 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.toUrl(page_arena)}); 805 } 806 807 // a link to the file's route. a preloaded file gets an "ai:" link 808 // (crossPageLink ignores it, so a click selects the row in place and shows its 809 // contents); an unloaded file gets an "a:" link, so activating it reloads the 810 // page with that file selected and its content read. 811 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8, loaded: bool) ![]const u8 { 812 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 813 const prefix = if (loaded) "ai:" else "a:"; 814 return std.fmt.allocPrint(page_arena.allocator(), "{s}{s}", .{ prefix, try route.toUrl(page_arena) }); 815 } 816 817 // the url `line` value for a content window: its first line's 1-based number, 818 // except the first window, which serializes as unset (0). 819 fn lineNumber(window_start: usize) usize { 820 return if (window_start == 0) 0 else window_start + 1; 821 } 822 823 // `dir`/`name`, or just `name` at the root. 824 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 825 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 826 } 827 828 // `dir` with its last segment removed ("" when `dir` has a single segment). 829 fn parentDir(dir: []const u8) []const u8 { 830 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 831 return dir[0..slash]; 832 } 833 834 // the "viewing <ref_or_oid> <value>" banner shown above the listing. 835 pub const Header = struct { 836 content: []const u8, 837 838 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 839 return .{ 840 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), value }), 841 }; 842 } 843 844 pub const View = struct { 845 box: wgt.Box(ui.Widget), 846 data: *const Header, 847 848 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 849 _ = session; 850 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 851 errdefer box.deinit(allocator); 852 853 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 854 errdefer text_box.deinit(allocator); 855 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null }); 856 857 return .{ .box = box, .data = data }; 858 } 859 860 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 861 self.box.deinit(allocator); 862 } 863 864 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 865 self.clearGrid(); 866 try self.box.build(allocator, constraint, root_focus); 867 } 868 869 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 870 _ = self; 871 _ = allocator; 872 _ = key; 873 _ = root_focus; 874 } 875 876 pub fn clearGrid(self: *Header.View) void { 877 self.box.clearGrid(); 878 } 879 880 pub fn getGrid(self: Header.View) ?Grid { 881 return self.box.getGrid(); 882 } 883 884 pub fn getFocus(self: *Header.View) *Focus { 885 return self.box.getFocus(); 886 } 887 }; 888 }; 889