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