╭ 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 = 2000; 18 19 // the most directory entries (files + dirs) we read from a tree and display. 20 // each file's content is also loaded (windowed), so an unbounded directory could 21 // add up to a lot of memory; entries past this limit are ignored. 22 // 23 // TODO: this caps what we keep, but `tr.Tree.init` still flattens the entire 24 // repo tree (every path) into memory before we ever apply the cap. read the 25 // directory level-by-level instead, using `obj.Object` to load one tree object 26 // at a time: initCommit -> root tree, then descend each `dir` segment, reading 27 // only the immediate entries of the target tree (and applying max_entries 28 // there). that bounds the work to O(depth) tree objects rather than the whole 29 // repo. it's doable entirely in haxy (no xit change) — `obj.Object(...).init` 30 // on a tree oid already returns just that tree's immediate children. 31 const max_entries = 100; 32 33 // one entry in the directory currently being viewed. 34 pub const Entry = struct { 35 name: []const u8, 36 is_dir: bool, 37 // a file's content window split into lines (each without its trailing 38 // newline); empty for directories and for binary or empty files. 39 lines: []const []const u8 = &.{}, 40 // true when xit's line iterator flagged the file as binary, so the detail 41 // pane shows a placeholder rather than its bytes. 42 is_binary: bool = false, 43 // the line index this window starts at (0 = the first window). non-zero only 44 // for the route's selected file, paginated by the url's `after`. 45 window_start: usize = 0, 46 // whether more lines exist after this window. 47 has_more: bool = false, 48 }; 49 50 // "owner/name", so the view can build /repo/owner/name/files/... links. 51 identity: []const u8, 52 // the resolved ref this listing is read at (the default branch when the route 53 // didn't name one), so the view's directory links stay pinned to it. 54 ref_or_oid: ui.RoutablePage.RefOrOid, 55 ref_or_oid_value: []const u8, 56 // the directory being viewed, relative to the repo root ("" at the root). 57 dir: []const u8, 58 // a file within `dir` to start selected (so its contents show and the url 59 // carries it), or null to fall back to a README / the first row. set when the 60 // route's path named a file rather than a directory. 61 selected_file: ?[]const u8 = null, 62 entries: []const Entry, 63 // the "viewing <ref> <value>" banner shown above the listing. 64 header: Header, 65 66 const Self = @This(); 67 68 // build the listing for an opened repo. generic over the repo's backend and 69 // hash kind so the tree/diff types it threads through match the repo's opts. 70 // reads with the arena's backing allocator (transient); the listing is built 71 // into the page arena so it outlives the repo handle. 72 pub fn init( 73 comptime repo_kind: rp.RepoKind, 74 comptime repo_opts: rp.RepoOpts(repo_kind), 75 arena: *std.heap.ArenaAllocator, 76 repo: *rp.Repo(repo_kind, repo_opts), 77 io: std.Io, 78 gpa: std.mem.Allocator, 79 identity: []const u8, 80 requested_ref_or_oid: ?ui.RoutablePage.RefOrOid, 81 requested_value: []const u8, 82 path: []const u8, 83 after: usize, 84 ) !Self { 85 const aa = arena.allocator(); 86 87 // resolve the requested ref (or the default branch) to the commit oid whose 88 // tree we list. a ref the route named explicitly that doesn't resolve is a 89 // bad url (NotFound -> 404); the default-branch path falls through to empty. 90 const resolved = (try ui.ResolvedRefOrOid(repo_kind, repo_opts).init(repo, io, aa, requested_ref_or_oid, requested_value)) orelse { 91 if (requested_ref_or_oid != null) return error.NotFound; 92 return emptyResult(aa, identity, .branch, requested_value, path); 93 }; 94 95 // read the tree at that commit. building the read-only state mirrors what 96 // repo.status does internally, but for an arbitrary commit rather than HEAD. 97 var moment = repo.core.latestMoment() catch return emptyResult(aa, identity, resolved.ref_or_oid, resolved.value, path); 98 const state = rp.Repo(repo_kind, repo_opts).State(.read_only){ .core = &repo.core, .extra = .{ .moment = &moment } }; 99 var tree = tr.Tree(repo_kind, repo_opts).init(state, io, gpa, &resolved.oid) catch return emptyResult(aa, identity, resolved.ref_or_oid, resolved.value, path); 100 defer tree.deinit(); 101 102 // `path` names a file when it's an exact tree entry: list its parent 103 // directory and start that file selected. otherwise `path` is the directory. 104 var dir = path; 105 var selected_file: ?[]const u8 = null; 106 if (path.len != 0 and tree.entries.get(path) != 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 // collect the immediate children of `dir`. each committed path is a full 113 // file path; a child is a directory when more path follows its first 114 // segment under `dir`. 115 var children: std.StringArrayHashMapUnmanaged(bool) = .empty; // name -> is_dir 116 defer children.deinit(gpa); 117 const prefix_len = if (dir.len == 0) 0 else dir.len + 1; // skip "dir/" 118 for (tree.entries.keys()) |entry_path| { 119 if (dir.len != 0) { 120 if (!std.mem.startsWith(u8, entry_path, dir) or entry_path.len <= dir.len or entry_path[dir.len] != '/') continue; 121 } 122 const rel = entry_path[prefix_len..]; 123 const slash = std.mem.indexOfScalar(u8, rel, '/'); 124 const name = if (slash) |s| rel[0..s] else rel; 125 const is_dir = slash != null; 126 // stop taking new entries once we hit the cap; the rest are ignored. 127 if (children.count() >= max_entries and !children.contains(name)) continue; 128 const gop = try children.getOrPut(gpa, name); 129 if (!gop.found_existing) gop.value_ptr.* = is_dir else if (is_dir) gop.value_ptr.* = true; 130 } 131 132 // trees hold no empty directories, so a non-root `dir` with no children 133 // doesn't exist in this ref — a bad url (404). 134 if (dir.len != 0 and children.count() == 0) return error.NotFound; 135 136 // committed paths come out sorted (tree objects are written in sorted 137 // order), so the deduped children are already in name order. just group 138 // directories before files, keeping that order within each group, and dupe 139 // into the page arena. each file's contents are read here (into the page 140 // arena) so the detail pane can show them without another lookup. 141 const entries = try aa.alloc(Entry, children.count()); 142 var i: usize = 0; 143 for ([_]bool{ true, false }) |want_dir| { 144 for (children.keys(), children.values()) |name, is_dir| { 145 if (is_dir != want_dir) continue; 146 var entry: Entry = .{ .name = try aa.dupe(u8, name), .is_dir = is_dir }; 147 if (!is_dir) { 148 const file_path = try childDir(aa, dir, name); 149 if (tree.entries.get(file_path)) |tree_entry| { 150 // only the route's selected file paginates; the rest show 151 // their first window (for the in-page detail when selected). 152 const is_selected = if (selected_file) |sf| std.mem.eql(u8, sf, name) else false; 153 const window_start = if (is_selected) after else 0; 154 const content = readFileContent(repo_kind, repo_opts, state, io, gpa, aa, file_path, tree_entry, window_start) catch 155 FileContent{ .lines = &.{} }; 156 entry.lines = content.lines; 157 entry.is_binary = content.is_binary; 158 entry.window_start = window_start; 159 entry.has_more = content.has_more; 160 } 161 } 162 entries[i] = entry; 163 i += 1; 164 } 165 } 166 167 return .{ 168 .identity = try aa.dupe(u8, identity), 169 .ref_or_oid = resolved.ref_or_oid, 170 .ref_or_oid_value = resolved.value, 171 .dir = try aa.dupe(u8, dir), 172 .selected_file = selected_file, 173 .entries = entries, 174 .header = try Header.init(aa, resolved.ref_or_oid, resolved.value), 175 }; 176 } 177 178 const FileContent = struct { 179 lines: []const []const u8, 180 is_binary: bool = false, 181 has_more: bool = false, 182 }; 183 184 // read the window [start, start+file_page) of a committed file's contents at 185 // `tree_entry` into `arena`-owned lines, flagging whether more follow. xit's 186 // line iterator flags binary files (its source becomes `.binary`), in which case 187 // we report no lines and let the view show a placeholder. 188 fn readFileContent( 189 comptime repo_kind: rp.RepoKind, 190 comptime repo_opts: rp.RepoOpts(repo_kind), 191 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 192 io: std.Io, 193 gpa: std.mem.Allocator, 194 arena: std.mem.Allocator, 195 path: []const u8, 196 tree_entry: tr.TreeEntry(repo_opts.hash), 197 start: usize, 198 ) !FileContent { 199 var line_iter = try df.LineIterator(repo_kind, repo_opts).initFromTree(state, io, gpa, path, tree_entry); 200 defer line_iter.deinit(); 201 if (line_iter.source == .binary) return .{ .lines = &.{}, .is_binary = true }; 202 203 // init reads through the file to validate it (and buffer it in memory), so 204 // the line count is known and a window can be sliced out of the buffer. 205 const total = line_iter.count(); 206 const end = @min(start + file_page, total); 207 208 var lines: std.ArrayList([]const u8) = .empty; 209 var i = start; 210 while (i < end) : (i += 1) { 211 const line = try line_iter.get(i); 212 defer line_iter.free(line); 213 try lines.append(arena, try arena.dupe(u8, line)); 214 } 215 return .{ 216 .lines = try lines.toOwnedSlice(arena), 217 .has_more = end < total, 218 }; 219 } 220 221 // an empty listing pinned to a ref, for the wasm / no-repo / unresolved paths. 222 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 { 223 return .{ 224 .identity = try aa.dupe(u8, identity), 225 .ref_or_oid = ref_or_oid, 226 .ref_or_oid_value = try aa.dupe(u8, ref_or_oid_value), 227 .dir = try aa.dupe(u8, dir), 228 .entries = &.{}, 229 .header = try Header.init(aa, ref_or_oid, ref_or_oid_value), 230 }; 231 } 232 233 pub const View = struct { 234 // a vertical stack: the "viewing <ref>" banner on top, then a horizontal 235 // split with the file/directory list on the left and a detail pane on the 236 // right showing the selected file's contents. 237 box: wgt.Box(ui.Widget), // vert: [header_index] = banner, [content_index] = split 238 data: *const Self, 239 session: *ui.Session, 240 // the list row whose contents the detail pane currently shows. 241 shown_index: ?usize, 242 243 const header_index: usize = 0; 244 const content_index: usize = 1; 245 // indices within the content box (the horizontal split). 246 const list_index: usize = 0; 247 const detail_index: usize = 1; 248 // indices within the detail pane frame (nav box above the content scroll). 249 const detail_nav_index: usize = 0; 250 const detail_scroll_index: usize = 1; 251 const list_max_width: usize = 40; 252 const detail_min_width: usize = 40; 253 254 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 255 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 256 errdefer outer.deinit(allocator); 257 258 // the ref banner at the top. 259 { 260 var header = try Header.View.init(allocator, &data.header, session); 261 errdefer header.deinit(allocator); 262 try outer.children.put(allocator, header.getFocus().id, .{ .widget = .{ .repo_files_header = header }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 263 } 264 265 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 266 errdefer box.deinit(allocator); 267 268 // the directory listing on the left (one focusable row each). 269 { 270 var list_scroll = blk: { 271 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 272 errdefer list_box.deinit(allocator); 273 274 // labels and link kinds are borrowed by the rows, so they live in 275 // the page arena (as long as this page's widget tree). 276 const aa = session.page_arena.allocator(); 277 if (data.dir.len != 0) { 278 try addRow(allocator, &list_box, "..", try dirLink(session.page_arena, data, parentDir(data.dir))); 279 } 280 for (data.entries) |entry| { 281 const path = try childDir(aa, data.dir, entry.name); 282 const label = if (entry.is_dir) try std.fmt.allocPrint(aa, "{s}/", .{entry.name}) else entry.name; 283 const link = if (entry.is_dir) 284 try dirLink(session.page_arena, data, path) 285 else 286 try fileLink(session.page_arena, data, path); 287 try addRow(allocator, &list_box, label, link); 288 } 289 // select the file the route named, else prefer a README so its 290 // contents greet the visitor in the detail pane, else the first 291 // row. a non-root directory has a leading ".." row, so the entry 292 // index is offset by one there. 293 if (list_box.children.count() > 0) { 294 const base: usize = if (data.dir.len != 0) 1 else 0; 295 const entry_idx = selectedFileIndex(data) orelse readmeIndex(data.entries); 296 const sel = if (entry_idx) |i| i + base else 0; 297 list_box.getFocus().child_id = list_box.children.keys()[sel]; 298 } 299 break :blk try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal }); 300 }; 301 errdefer list_scroll.deinit(allocator); 302 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 } }); 303 } 304 305 // the detail pane on the right — a "next" nav box above a scroll of the 306 // selected file's content window. both are repopulated per selection by 307 // populateDetail. 308 { 309 var detail_outer = blk: { 310 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 311 errdefer frame.deinit(allocator); 312 313 { 314 var nav_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 315 errdefer nav_box.deinit(allocator); 316 try frame.children.put(allocator, nav_box.getFocus().id, .{ .widget = .{ .box = nav_box }, .rect = null, .min_size = null }); 317 } 318 { 319 // the content scroll wrapped in a bordered box; build sets the 320 // border single normally and double when the content is focused 321 // (the content box itself is borderless). 322 var scroll_frame = blk2: { 323 var detail_scroll = blk3: { 324 var detail_inner = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 325 errdefer detail_inner.deinit(allocator); 326 break :blk3 try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_inner }, .{ .direction = .both, .web_native = !session.is_terminal, .fill = true }); 327 }; 328 errdefer detail_scroll.deinit(allocator); 329 var sf = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .single, .rounded_corners = true, .direction = .vert }); 330 errdefer sf.deinit(allocator); 331 // the wrapper's selected child is its scroll, so the focus 332 // chain reaches the content box (populateDetail points the 333 // scroll's inner box at it). 334 sf.getFocus().child_id = detail_scroll.getFocus().id; 335 try sf.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = null }); 336 break :blk2 sf; 337 }; 338 errdefer scroll_frame.deinit(allocator); 339 // entering the detail pane lands on the content scroll (focus 340 // recovery descends the frame's selected child). the nav links 341 // above are reached by scrolling to the top, then up. 342 frame.getFocus().child_id = scroll_frame.getFocus().id; 343 try frame.children.put(allocator, scroll_frame.getFocus().id, .{ .widget = .{ .box = scroll_frame }, .rect = null, .min_size = null }); 344 } 345 break :blk frame; 346 }; 347 errdefer detail_outer.deinit(allocator); 348 try box.children.put(allocator, detail_outer.getFocus().id, .{ .widget = .{ .box = detail_outer }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 349 } 350 351 box.getFocus().child_id = box.children.keys()[list_index]; 352 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 353 354 // focus lives in the split; the banner isn't focusable. 355 outer.getFocus().child_id = outer.children.keys()[content_index]; 356 return .{ .box = outer, .data = data, .session = session, .shown_index = null }; 357 } 358 359 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 360 var row = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 361 errdefer row.deinit(allocator); 362 row.getFocus().focusable = true; 363 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 364 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null }); 365 } 366 367 // the selected file's contents as a single focusable multi-line text box. 368 // it's borderless — the border lives on the surrounding scroll frame, which 369 // doubles when this content is focused. `text` lives in the page arena. 370 fn addContentBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), text: []const u8) !void { 371 _ = self; 372 var tb = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = null, .wrap_kind = .none }); 373 errdefer tb.deinit(allocator); 374 tb.getFocus().focusable = true; 375 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 376 } 377 378 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 379 self.box.deinit(allocator); 380 } 381 382 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 383 return &self.box.children.values()[content_index].widget.box; 384 } 385 386 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 387 return &self.contentBox().children.values()[list_index].widget.scroll; 388 } 389 390 fn listBox(self: *View) *wgt.Box(ui.Widget) { 391 return &self.listScroll().child.box; 392 } 393 394 fn detailOuter(self: *View) *wgt.Box(ui.Widget) { 395 return &self.contentBox().children.values()[detail_index].widget.box; 396 } 397 398 fn navBox(self: *View) *wgt.Box(ui.Widget) { 399 return &self.detailOuter().children.values()[detail_nav_index].widget.box; 400 } 401 402 // the bordered box wrapping the content scroll (border toggles with focus). 403 fn detailScrollFrame(self: *View) *wgt.Box(ui.Widget) { 404 return &self.detailOuter().children.values()[detail_scroll_index].widget.box; 405 } 406 407 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 408 return &self.detailScrollFrame().children.values()[0].widget.scroll; 409 } 410 411 fn detailInner(self: *View) *wgt.Box(ui.Widget) { 412 return &self.detailScroll().child.box; 413 } 414 415 fn detailActive(self: *View) bool { 416 const content = self.contentBox(); 417 const cid = content.getFocus().child_id orelse return false; 418 return content.children.getIndex(cid) == detail_index; 419 } 420 421 // the selected list row's index, or null when nothing is focused. 422 fn selectedRowIndex(self: *View) ?usize { 423 const lb = self.listBox(); 424 const cid = lb.getFocus().child_id orelse return null; 425 return lb.children.getIndex(cid); 426 } 427 428 // the entry the selected row points at, or null for the ".." row (which 429 // isn't an entry). directory rows return their entry too, though they carry 430 // no contents. 431 fn selectedEntry(self: *View) ?Entry { 432 const idx = self.selectedRowIndex() orelse return null; 433 const base: usize = if (self.data.dir.len != 0) 1 else 0; // skip the ".." row 434 if (idx < base) return null; 435 const e = idx - base; 436 if (e >= self.data.entries.len) return null; 437 return self.data.entries[e]; 438 } 439 440 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 441 self.clearGrid(); 442 443 // swap the detail pane to the selected entry when the selection changes. 444 try self.refreshDetail(allocator); 445 446 // mirror the selected file into the url so it updates as the selection 447 // moves, but only while focus is inside this view (so landing on the tab 448 // keeps the page's base route). a file selection carries the file path and 449 // its content window offset; a directory / ".." row (or no selection) 450 // stays at the directory with no offset. the path is joined in a stack 451 // buffer since build runs every frame on the web. 452 if (root_focus.grandchild_id) |g| { 453 if (self.box.getFocus().children.contains(g)) { 454 var buf: [ui.RoutablePage.repo_route_max_len]u8 = undefined; 455 var sel_path = self.data.dir; 456 var sel_after: usize = 0; 457 if (self.selectedEntry()) |entry| { 458 if (!entry.is_dir) { 459 sel_path = if (self.data.dir.len == 0) 460 entry.name 461 else 462 std.fmt.bufPrint(&buf, "{s}/{s}", .{ self.data.dir, entry.name }) catch self.data.dir; 463 sel_after = entry.window_start; 464 } 465 } 466 if (ui.RoutablePage.repoFilesRoute(self.data.identity, self.data.ref_or_oid, self.data.ref_or_oid_value, sel_path, sel_after)) |route| 467 self.session.data.current_page = route; 468 } 469 } 470 471 // the selected list row shows a border (the focused TextBox upgrades it 472 // to a double border itself); the rest stay borderless. 473 const lb = self.listBox(); 474 for (lb.children.keys(), lb.children.values()) |id, *child| { 475 switch (child.widget) { 476 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 477 else => {}, 478 } 479 } 480 481 // the content scroll's border is single normally and double when the 482 // content is focused (the content box itself is borderless). 483 const has_content = self.detailInner().children.count() > 0; 484 const content_focused = if (root_focus.grandchild_id) |g| self.detailInner().children.contains(g) else false; 485 self.detailScrollFrame().options.border_style = if (!has_content) null else if (content_focused) .double else .single; 486 487 // same for the "next" link above the content. 488 const nav_box = self.navBox(); 489 for (nav_box.children.keys(), nav_box.children.values()) |id, *child| { 490 switch (child.widget) { 491 .text_box => |*tb| tb.options.border_style = if (nav_box.getFocus().child_id == id) .single else .hidden, 492 else => {}, 493 } 494 } 495 496 // cap the list at list_max_width only while the detail pane fits beside 497 // it. the box drops the detail pane when the width can't hold both 498 // minimums, so when it's that narrow we lift the cap and let the list 499 // fill the whole width. 500 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 501 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 502 503 // stretch the detail pane and its bordered scroll frame across the rest 504 // of the width so the pane fills the area rather than shrinking to its 505 // content, like the refs view's columns. the content scroll inside keeps 506 // its natural width: forcing it to the full inner width would make it one 507 // column too wide whenever the vertical scrollbar appears, leaving a 508 // phantom horizontal scroll. (height fills via the scroll clipping to the 509 // viewport.) 510 if (constraint.max_size.width) |w| { 511 const detail_w = if (both_panes_fit) w - list_max_width else w; 512 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_w, .height = null }; 513 self.detailOuter().children.values()[detail_scroll_index].min_size = .{ .width = detail_w, .height = null }; 514 } else { 515 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 516 self.detailOuter().children.values()[detail_scroll_index].min_size = null; 517 } 518 519 // crossing panes only re-selects the content box's child (focusList / 520 // focusDetail); when the window is too narrow to show both, the pane that 521 // was holding focus is dropped here. the framework recovers focus after 522 // the top-level build by re-deriving it down the selected-child chain, so 523 // there's nothing to fix up afterward. 524 try self.box.build(allocator, constraint, root_focus); 525 } 526 527 fn refreshDetail(self: *View, allocator: std.mem.Allocator) !void { 528 const cur = self.selectedRowIndex(); 529 if (std.meta.eql(cur, self.shown_index)) return; 530 try self.populateDetail(allocator); 531 self.shown_index = cur; 532 } 533 534 fn populateDetail(self: *View, allocator: std.mem.Allocator) !void { 535 const nav_box = self.navBox(); 536 const inner = self.detailInner(); 537 538 for (nav_box.children.values()) |*child| child.widget.deinit(allocator); 539 nav_box.children.clearAndFree(allocator); 540 nav_box.getFocus().child_id = null; 541 for (inner.children.values()) |*child| child.widget.deinit(allocator); 542 inner.children.clearAndFree(allocator); 543 inner.getFocus().child_id = null; 544 545 // only files have contents to show; directories and the ".." row leave 546 // the pane empty. 547 if (self.selectedEntry()) |entry| { 548 if (!entry.is_dir) { 549 // the "next" window link sits above the scroll, so it stays put 550 // while the content scrolls. 551 if (entry.has_more) try self.addNavLink(allocator, nav_box, "next lines →", entry, entry.window_start + file_page); 552 if (entry.is_binary) { 553 try self.addContentBox(allocator, inner, "(binary file)"); 554 } else { 555 const text = try numberedContent(self.session.page_arena.allocator(), entry.lines, entry.window_start); 556 try self.addContentBox(allocator, inner, text); 557 } 558 } 559 } 560 // point each box at its first child so focus can descend into it. 561 if (nav_box.children.count() > 0) nav_box.getFocus().child_id = nav_box.children.keys()[0]; 562 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 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_after`, 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_after: 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_after) orelse return error.RouteTooLong; 580 const link = try std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.urlAlloc(page_arena)}); 581 var tb = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .hidden, .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) continue; 783 if (std.ascii.eqlIgnoreCase(entry.name, "README") or std.ascii.eqlIgnoreCase(entry.name, "README.md")) 784 return i; 785 } 786 return null; 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.urlAlloc(page_arena)}); 803 } 804 805 // an "ai:" link to the file's route: crossPageLink ignores it, so a wasm click 806 // selects the row in place and shows its contents in the detail pane. 807 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 808 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 809 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.urlAlloc(page_arena)}); 810 } 811 812 // `dir`/`name`, or just `name` at the root. 813 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 814 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 815 } 816 817 // `dir` with its last segment removed ("" when `dir` has a single segment). 818 fn parentDir(dir: []const u8) []const u8 { 819 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 820 return dir[0..slash]; 821 } 822 823 // the "viewing <ref_or_oid> <value>" banner shown above the listing. 824 pub const Header = struct { 825 content: []const u8, 826 827 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 828 return .{ 829 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), value }), 830 }; 831 } 832 833 pub const View = struct { 834 text_box: wgt.TextBox(ui.Widget), 835 data: *const Header, 836 837 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 838 _ = session; 839 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 840 errdefer text_box.deinit(allocator); 841 return .{ .text_box = text_box, .data = data }; 842 } 843 844 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 845 self.text_box.deinit(allocator); 846 } 847 848 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 849 // a single line plus the hidden border is 3 rows tall; stretch the box to 850 // the full width by handing the available width down as a min width. 851 try self.text_box.build(allocator, .{ 852 .min_size = .{ .width = constraint.max_size.width, .height = null }, 853 .max_size = constraint.max_size, 854 }, root_focus); 855 } 856 857 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 858 _ = self; 859 _ = allocator; 860 _ = key; 861 _ = root_focus; 862 } 863 864 pub fn clearGrid(self: *Header.View) void { 865 self.text_box.clearGrid(); 866 } 867 868 pub fn getGrid(self: Header.View) ?Grid { 869 return self.text_box.getGrid(); 870 } 871 872 pub fn getFocus(self: *Header.View) *Focus { 873 return self.text_box.getFocus(); 874 } 875 }; 876 }; 877