╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
272 if (preloaded_bytes.* >= max_preloaded_bytes and !is_selected and !isReadme(name)) return entry; 273 const file_path = try childDir(aa, dir, name); 274 // the url's `line` is 1-based (0 = unset); the window index is 0-based. 275 const window_start = if (is_selected) line -| 1 else 0; 276 const content = readFileContent(repo_kind, repo_opts, state, io, gpa, aa, file_path, oid, mode, window_start) catch 277 FileContent{ .lines = &.{} }; 278 for (content.lines) |l| preloaded_bytes.* += l.len; 279 entry.lines = content.lines; 280 entry.is_binary = content.is_binary; 281 entry.window_start = window_start; 282 entry.has_more = content.has_more; 283 entry.loaded = true; 284 return entry; 285 } 286 287 const FileContent = struct { 288 lines: []const []const u8, 289 is_binary: bool = false, 290 has_more: bool = false, 291 }; 292 293 // read the window [start, start+file_page) of a committed file's contents at 294 // `oid` into `arena`-owned lines, flagging whether more follow. xit's 295 // line iterator flags binary files (its source becomes `.binary`), in which case 296 // we report no lines and let the view show a placeholder. 297 fn readFileContent( 298 comptime repo_kind: rp.RepoKind, 299 comptime repo_opts: rp.RepoOpts(repo_kind), 300 state: rp.Repo(repo_kind, repo_opts).State(.read_only), 301 io: std.Io, 302 gpa: std.mem.Allocator, 303 arena: std.mem.Allocator, 304 path: []const u8, 305 oid: *const [xit.hash.byteLen(repo_opts.hash)]u8, 306 mode: ?xit.fs.Mode, 307 start: usize, 308 ) !FileContent { 309 var line_iter = try df.LineIterator(repo_kind, repo_opts).initFromOid(state, io, gpa, path, oid, mode); 310 defer line_iter.deinit(); 311 if (line_iter.source == .binary) return .{ .lines = &.{}, .is_binary = true }; 312 313 // init reads through the file to validate it (and buffer it in memory), so 314 // the line count is known and a window can be sliced out of the buffer. 315 const total = line_iter.count(); 316 const end = @min(start +| file_page, total); 317 318 var lines: std.ArrayList([]const u8) = .empty; 319 var i = start; 320 while (i < end) : (i += 1) { 321 const line = try line_iter.get(i); 322 try lines.append(arena, try arena.dupe(u8, line)); 323 } 324 return .{ 325 .lines = try lines.toOwnedSlice(arena), 326 .has_more = end < total, 327 }; 328 } 329 330 // an empty listing pinned to a ref, for the wasm / no-repo / unresolved paths. 331 pub fn emptyResult(aa: std.mem.Allocator, handle: ui.RepoHandle, ref_or_oid: ui.RoutablePage.RefOrOid, ref_or_oid_value: []const u8, dir: []const u8) !Self { 332 return .{ 333 .handle = try handle.dupe(aa), 334 .ref_or_oid = ref_or_oid, 335 .ref_or_oid_value = try aa.dupe(u8, ref_or_oid_value), 336 .dir = try aa.dupe(u8, dir), 337 .entries = &.{}, 338 }; 339 } 340 341 pub const View = struct { 342 // a vertical stack: the search box and clone url on top, then a horizontal 343 // split with the file/directory list on the left and a detail pane on the 344 // right showing the selected file's contents. 345 box: wgt.Box(ui.Widget), // vert: [header_index] = header row, [content_index] = split 346 data: *const Self, 347 session: *ui.Session, 348 // what the detail pane was last filled for: the selected list row, and 349 // whether the window was too narrow to show the list beside it 350 shown: Shown = .{ .index = null, .narrow = false }, 351 // the detail's way back to a list that isn't shown beside it 352 back_id: ?usize = null, 353 354 const Shown = struct { index: ?usize, narrow: bool }; 355 356 // the sub-header leads the box where there is one; local mode has none 357 const header_index: usize = 0; 358 // indices within the content box (the horizontal split). 359 const list_index: usize = 0; 360 const detail_index: usize = 1; 361 // indices within the detail pane frame (nav box above the content scroll). 362 const detail_nav_index: usize = 0; 363 const detail_scroll_index: usize = 1; 364 const list_max_width: usize = 35; 365 const detail_min_width: usize = 40; 366 // a list row's height: one text line inside its (hidden) border. 367 const row_height: usize = 3; 368 369 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 370 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert }); 371 errdefer outer.deinit(allocator); 372 373 if (data.no_commits) { 374 var center = try ui.widget.initNoCommits(allocator, session, data.handle); 375 errdefer center.deinit(allocator); 376 outer.getFocus().child_id = center.getFocus().id; 377 try outer.children.put(allocator, center.getFocus().id, .{ .widget = .{ .center = center }, .rect = null, .min_size = null }); 378 return .{ .box = outer, .data = data, .session = session }; 379 } 380 381 // the search box and the clone url at the top. local mode has neither. 382 if (session.data.host_kind == .server) { 383 var header_view = try ui.widget.SearchHeader.init(allocator, session, data.handle, " find file ", "find", data.find, data.find_available); 384 errdefer header_view.deinit(allocator); 385 // a row taller than the header, leaving a blank line beneath it 386 try outer.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .search_header = header_view }, .rect = null, .min_size = .{ .width = null, .height = 4 } }); 387 } 388 389 // an empty root listing shows the empty message in place of the split 390 if (data.isEmpty()) { 391 var center = try ui.widget.initEmpty(allocator); 392 errdefer center.deinit(allocator); 393 try outer.children.put(allocator, center.getFocus().id, .{ .widget = .{ .center = center }, .rect = null, .min_size = null }); 394 // with nothing below to focus, focus rests on the sub-header 395 outer.getFocus().child_id = outer.children.keys()[header_index]; 396 return .{ .box = outer, .data = data, .session = session }; 397 } 398 399 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .horiz }); 400 errdefer box.deinit(allocator); 401 402 var shows_file = false; 403 404 // the directory listing on the left (one focusable row each). 405 { 406 var list_scroll = blk: { 407 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert, .stretch = true }); 408 errdefer list_box.deinit(allocator); 409 410 // link kinds are borrowed by the rows, so they live in the page 411 // arena (as long as this page's widget tree). row labels are 412 // copied by their text boxes. 413 const aa = session.page_arena.allocator(); 414 if (data.dir.len != 0) { 415 try addRow(allocator, &list_box, "..", "", try dirLink(session.page_arena, data, parentDir(data.dir))); 416 } 417 for (data.entries) |entry| { 418 const path = try childDir(aa, data.dir, entry.name); 419 // a search result shows its file name, with its directory 420 // in the bottom label. 421 const label = if (data.find != null) 422 std.Io.Dir.path.basenamePosix(entry.name) 423 else if (entry.is_dir) 424 try aa.print("{s}/", .{entry.name}) 425 else 426 entry.name; 427 const bottom_label = if (data.find != null) try resultDirLabel(aa, entry.name) else ""; 428 const link = if (entry.is_dir) 429 try dirLink(session.page_arena, data, path) 430 else 431 try fileLink(session.page_arena, data, path, entry.loaded, lineNumber(entry.window_start)); 432 try addRow(allocator, &list_box, label, bottom_label, link); 433 } 434 if (data.capped) try addRow(allocator, &list_box, "(list truncated)", "", ""); 435 // select the file the route named, else prefer a README so its 436 // contents greet the visitor in the detail pane, else the first 437 // row. a non-root directory has a leading ".." row, so the entry 438 // index is offset by one there. search results have no README 439 // default: the term decides what matters. 440 var sel: usize = 0; 441 if (list_box.children.count() > 0) { 442 const base: usize = if (data.dir.len != 0) 1 else 0; 443 const entry_idx = selectedFileIndex(data) orelse if (data.find == null) readmeIndex(data.entries) else null; 444 sel = if (entry_idx) |i| i + base else 0; 445 list_box.getFocus().child_id = list_box.children.keys()[sel]; 446 shows_file = sel >= base and sel - base < data.entries.len and !data.entries[sel - base].is_dir; 447 } 448 var sc = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 449 // start scrolled so the selected row begins at the top of the 450 // viewport. rows are a fixed height, so no layout pass is 451 // needed; a too-far offset near the end of the list is clamped 452 // in build (the browser clamps its own scrolling natively). 453 sc.y = @intCast(sel * row_height); 454 break :blk sc; 455 }; 456 errdefer list_scroll.deinit(allocator); 457 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 } }); 458 } 459 460 // the detail pane on the right — a "next" nav box above a scroll of the 461 // selected file's content window. both are repopulated per selection by 462 // populateDetail. 463 { 464 var detail_outer = blk: { 465 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert }); 466 errdefer frame.deinit(allocator); 467 468 { 469 var nav_box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .horiz }); 470 errdefer nav_box.deinit(allocator); 471 try frame.children.put(allocator, nav_box.getFocus().id, .{ .widget = .{ .box = nav_box }, .rect = null, .min_size = null }); 472 } 473 { 474 // the content scroll wrapped in a bordered box; build sets the 475 // border single normally and double when the content is focused 476 // (the content box itself is borderless). 477 var scroll_frame = blk2: { 478 var detail_scroll = blk3: { 479 var detail_inner = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert }); 480 errdefer detail_inner.deinit(allocator); 481 break :blk3 try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_inner }, .{ .direction = .both, .web_native = !session.is_terminal, .fill = true }); 482 }; 483 errdefer detail_scroll.deinit(allocator); 484 var sf = try wgt.Box(ui.Widget).init(allocator, .{ .border = .single, .round_corners = true, .direction = .vert }); 485 errdefer sf.deinit(allocator); 486 // the wrapper's selected child is its scroll, so the focus 487 // chain reaches the content box (populateDetail points the 488 // scroll's inner box at it). 489 sf.getFocus().child_id = detail_scroll.getFocus().id; 490 try sf.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = null }); 491 break :blk2 sf; 492 }; 493 errdefer scroll_frame.deinit(allocator); 494 // entering the detail pane lands on the content scroll (focus 495 // recovery descends the frame's selected child). the nav links 496 // above are reached by scrolling to the top, then up. 497 frame.getFocus().child_id = scroll_frame.getFocus().id; 498 // shrink, so the fill scroll yields the nav box's row 499 // instead of consuming the frame's whole height. 500 try frame.children.put(allocator, scroll_frame.getFocus().id, .{ .widget = .{ .box = scroll_frame }, .rect = null, .min_size = null, .flex = .shrink }); 501 } 502 break :blk frame; 503 }; 504 errdefer detail_outer.deinit(allocator); 505 detail_outer.getFocus().mode = .mouse; 506 try box.children.put(allocator, detail_outer.getFocus().id, .{ .widget = .{ .box = detail_outer }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 507 } 508 509 box.getFocus().child_id = box.children.keys()[if (shows_file) detail_index else list_index]; 510 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 511 512 // focus lives in the split, except that search results start in the 513 // search box so the term can be refined right away. 514 outer.getFocus().child_id = outer.children.keys()[if (data.find != null) header_index else outer.children.count() - 1]; 515 return .{ .box = outer, .data = data, .session = session }; 516 } 517 518 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, bottom_label: []const u8, link: []const u8) !void { 519 var row = try wgt.TextBox.init(allocator, label, .{ .border = .hidden, .round_corners = true, .wrap_kind = .none, .bottom_label = .{ .text = bottom_label } }); 520 errdefer row.deinit(allocator); 521 row.getFocus().mode = .all; 522 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 523 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null }); 524 } 525 526 // the selected file's contents as a single focusable multi-line text box. 527 // it's borderless — the border lives on the surrounding scroll frame, which 528 // doubles when this content is focused. a non-empty `link` makes activating 529 // the box follow it, like addRow. 530 fn addContentBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), spans: []const wgt.Span, link: []const u8) !void { 531 _ = self; 532 var tb = try wgt.TextBox.initSpans(allocator, spans, .{ .border = null, .wrap_kind = .none }); 533 errdefer tb.deinit(allocator); 534 tb.getFocus().mode = .all; 535 if (link.len != 0) tb.getFocus().kind = .{ .custom = link }; 536 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 537 } 538 539 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 540 self.box.deinit(allocator); 541 } 542 543 // the split is last, after the sub-header where there is one 544 fn contentIndex(self: *View) usize { 545 return self.box.children.count() - 1; 546 } 547 548 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 549 return &self.box.children.values()[self.contentIndex()].widget.box; 550 } 551 552 fn header(self: *View) ?*ui.widget.SearchHeader { 553 switch (self.box.children.values()[header_index].widget) { 554 .search_header => |*header_view| return header_view, 555 else => return null, 556 } 557 } 558 559 fn headerActive(self: *View) bool { 560 const header_view = self.header() orelse return false; 561 return self.box.getFocus().child_id == header_view.getFocus().id; 562 } 563 564 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 565 return &self.contentBox().children.values()[list_index].widget.scroll; 566 } 567 568 fn listBox(self: *View) *wgt.Box(ui.Widget) { 569 return &self.listScroll().child.box; 570 } 571 572 fn detailOuter(self: *View) *wgt.Box(ui.Widget) { 573 return &self.contentBox().children.values()[detail_index].widget.box; 574 } 575 576 fn navBox(self: *View) *wgt.Box(ui.Widget) { 577 return &self.detailOuter().children.values()[detail_nav_index].widget.box; 578 } 579 580 // the bordered box wrapping the content scroll (border toggles with focus). 581 fn detailScrollFrame(self: *View) *wgt.Box(ui.Widget) { 582 return &self.detailOuter().children.values()[detail_scroll_index].widget.box; 583 } 584 585 fn detailScroll(self: *View) *wgt.Scroll(ui.Widget) { 586 return &self.detailScrollFrame().children.values()[0].widget.scroll; 587 } 588 589 fn detailInner(self: *View) *wgt.Box(ui.Widget) { 590 return &self.detailScroll().child.box; 591 } 592 593 fn detailActive(self: *View) bool { 594 const content = self.contentBox(); 595 const cid = content.getFocus().child_id orelse return false; 596 return content.children.getIndex(cid) == detail_index; 597 } 598 599 // the selected list row's index, or null when nothing is focused. 600 fn selectedRowIndex(self: *View) ?usize { 601 const lb = self.listBox(); 602 const cid = lb.getFocus().child_id orelse return null; 603 return lb.children.getIndex(cid); 604 } 605 606 // the entry the selected row points at, or null for the ".." row (which 607 // isn't an entry). directory rows return their entry too, though they carry 608 // no contents. 609 fn selectedEntry(self: *View) ?Entry { 610 const idx = self.selectedRowIndex() orelse return null; 611 const base: usize = if (self.data.dir.len != 0) 1 else 0; // skip the ".." row 612 if (idx < base) return null; 613 const e = idx - base; 614 if (e >= self.data.entries.len) return null; 615 return self.data.entries[e]; 616 } 617 618 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 619 self.clearGrid(); 620 if (self.data.no_commits or self.data.isEmpty()) return self.box.build(allocator, constraint, root_focus); 621 622 // whether the detail pane fits beside the list, which decides the list 623 // cap below and whether the detail carries a way back to the list 624 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 625 626 // swap the detail pane to the selected entry when the selection changes. 627 try self.refreshDetail(allocator, !both_panes_fit); 628 629 // the selected list row shows a border (the focused TextBox upgrades it 630 // to a double border itself); the rest stay borderless. 631 const lb = self.listBox(); 632 for (lb.children.keys(), lb.children.values()) |id, *child| { 633 switch (child.widget) { 634 .text_box => |*tb| ui.widget.markSelected(tb, lb.getFocus().child_id == id), 635 else => {}, 636 } 637 } 638 639 // the content scroll's border is single normally and double when the 640 // content is focused (the content box itself is borderless). 641 const has_content = self.detailInner().children.count() > 0; 642 self.detailScrollFrame().options.border = if (!has_content) null else if (self.focusOnContent(root_focus)) .double else .single; 643 644 // cap the list at list_max_width only while the detail pane fits beside 645 // it. the box drops the detail pane when the width can't hold both 646 // minimums, so when it's that narrow we lift the cap and let the list 647 // fill the whole width. 648 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 649 650 // stretch the detail pane and its bordered scroll frame across the rest 651 // of the width so the pane fills the area rather than shrinking to its 652 // content, like the refs view's columns. the content scroll inside keeps 653 // its natural width: forcing it to the full inner width would make it one 654 // column too wide whenever the vertical scrollbar appears, leaving a 655 // phantom horizontal scroll. (height fills via the scroll clipping to the 656 // viewport.) 657 if (constraint.max_size.width) |w| { 658 const detail_w = if (both_panes_fit) w - list_max_width else w; 659 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_w, .height = null }; 660 self.detailOuter().children.values()[detail_scroll_index].min_size = .{ .width = detail_w, .height = null }; 661 } else { 662 self.contentBox().children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 663 self.detailOuter().children.values()[detail_scroll_index].min_size = null; 664 } 665 666 // crossing panes only re-selects the content box's child (focusList / 667 // focusDetail); when the window is too narrow to show both, the pane that 668 // was holding focus is dropped here. the framework recovers focus after 669 // the top-level build by re-deriving it down the selected-child chain, so 670 // there's nothing to fix up afterward. 671 try self.box.build(allocator, constraint, root_focus); 672 673 // clamp the list's initial offset (a selected row near the end of the 674 // list) against this build's grids, for the next frame. initRoot's 675 // pre-sizing build is unbounded — its full-content "viewport" would 676 // clamp the offset to zero, so only a bounded build counts. 677 if (constraint.max_size.height != null) self.listScroll().clampToContent(); 678 } 679 680 fn refreshDetail(self: *View, allocator: std.mem.Allocator, narrow: bool) !void { 681 const next: Shown = .{ .index = self.selectedRowIndex(), .narrow = narrow }; 682 if (std.meta.eql(next, self.shown)) return; 683 try self.populateDetail(allocator, narrow); 684 self.shown = next; 685 } 686 687 fn populateDetail(self: *View, allocator: std.mem.Allocator, narrow: bool) !void { 688 const nav_box = self.navBox(); 689 const inner = self.detailInner(); 690 691 for (nav_box.children.values()) |*child| child.widget.deinit(allocator); 692 nav_box.children.clearAndFree(allocator); 693 nav_box.getFocus().child_id = null; 694 for (inner.children.values()) |*child| child.widget.deinit(allocator); 695 inner.children.clearAndFree(allocator); 696 inner.getFocus().child_id = null; 697 self.back_id = null; 698 699 // only files have contents to show; directories and the ".." row leave 700 // the pane empty. 701 var markdown = false; 702 self.detailScrollFrame().options.top_label.text = ""; 703 if (self.selectedEntry()) |entry| { 704 if (!entry.is_dir) { 705 const path = try childDir(self.session.page_arena.allocator(), self.data.dir, entry.name); 706 // the frame around the contents is labeled with the file's name 707 self.detailScrollFrame().options.top_label.text = try self.session.page_arena.allocator().print(" {s} ", .{entry.name}); 708 // with the list hidden beside it, the detail leads with the way 709 // back. an in-page link to this very page, so both hosts hand 710 // its press and enter to detailInput instead of navigating. 711 if (narrow) { 712 const page_arena = self.session.page_arena; 713 const link = try page_arena.allocator().print("ai:{s}", .{try self.session.data.current_page.toUrl(page_arena)}); 714 self.back_id = try addNavButton(allocator, nav_box, "← back to file list", link); 715 } 716 // the window links sit above the scroll, so they stay put 717 // while the content scrolls. 718 if (entry.window_start > 0) try self.addNavLink(allocator, nav_box, "scroll to top", entry, 0); 719 if (entry.has_more) try self.addNavLink(allocator, nav_box, "next lines →", entry, lineNumber(entry.window_start + file_page)); 720 if (!entry.loaded) { 721 // the placeholder carries the file's "a:" link, so enter 722 // (or a click) here loads the file like on its list row. 723 const link = try fileLink(self.session.page_arena, self.data, path, false, 0); 724 try self.addContentBox(allocator, inner, &.{.{ .text = "(press enter to load this file)" }}, link); 725 } else if (entry.is_binary) { 726 try self.addContentBox(allocator, inner, &.{.{ .text = "(binary file)" }}, ""); 727 } else if (isMarkdown(entry.name) and entry.window_start == 0 and !entry.has_more and entry.lines.len <= max_markdown_lines) { 728 const page_arena = self.session.page_arena; 729 const doc = try md.parse(page_arena.allocator(), entry.lines); 730 var view = try Markdown.View.init(allocator, doc, self.data, path, page_arena); 731 errdefer view.deinit(allocator); 732 try inner.children.put(allocator, view.getFocus().id, .{ .widget = .{ .markdown = view }, .rect = null, .min_size = null }); 733 markdown = true; 734 } else { 735 try self.addContentBox(allocator, inner, try numberedContent(self.session.page_arena, self.data, path, entry.lines, entry.window_start), ""); 736 } 737 } 738 } 739 // point each box at its first child so focus can descend into it, and 740 // the pane at its nav row when it has one, else at the content 741 if (nav_box.children.count() > 0) nav_box.getFocus().child_id = nav_box.children.keys()[0]; 742 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 743 self.detailOuter().getFocus().child_id = if (nav_box.children.count() > 0) nav_box.getFocus().id else self.detailScrollFrame().getFocus().id; 744 745 // reserve the nav row's height (the shrink scroll frame yields it). 746 self.detailOuter().children.values()[detail_nav_index].min_size = 747 if (nav_box.children.count() > 0) .{ .width = null, .height = row_height } else null; 748 749 // rendered markdown wraps to the pane's width, so it only scrolls down 750 const sc = self.detailScroll(); 751 sc.options.direction = if (markdown) .vert else .both; 752 753 // reset the scroll to the top for the newly-shown file: directly on the 754 // terminal (the wasm offset), and via a version bump on the web (so the 755 // renderer's scroll id changes and JS drops the preserved position). 756 sc.x = 0; 757 sc.y = 0; 758 sc.getFocus().version +%= 1; 759 } 760 761 // a focusable "next" link above the content. it's an `a:` link to the 762 // selected file at `target_start`, so activating it (the host follows the 763 // link) reloads the page on the next window. 764 fn addNavLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, entry: Entry, target_start: usize) !void { 765 const page_arena = self.session.page_arena; 766 const path = try childDir(page_arena.allocator(), self.data.dir, entry.name); 767 const route = self.data.filesRoute(path, target_start) orelse return error.RouteTooLong; 768 const link = try page_arena.allocator().print("a:{s}", .{try route.toUrl(page_arena)}); 769 _ = try addNavButton(allocator, box, label, link); 770 } 771 772 // a bordered button in the nav row carrying `link`, returning its focus id 773 fn addNavButton(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !usize { 774 var tb = try wgt.TextBox.init(allocator, label, .{ .border = .single, .round_corners = true, .wrap_kind = .none }); 775 errdefer tb.deinit(allocator); 776 tb.getFocus().mode = .all; 777 tb.getFocus().kind = .{ .custom = link }; 778 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 779 return tb.getFocus().id; 780 } 781 782 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 783 if (self.data.no_commits) return self.box.input(allocator, key, root_focus); 784 // scrolling crosses the sub header boundary the same way arrows do 785 const direction = inp.vertDirection(key); 786 if (self.headerActive()) { 787 // active means there is one 788 const header_view = self.header() orelse unreachable; 789 if (direction == .down) { 790 // the empty message has nothing to focus 791 if (!self.data.isEmpty()) root_focus.setFocus(self.contentBox().getFocus().id); 792 return; 793 } 794 if (key == .enter) if (try header_view.submittedText(allocator)) |term| { 795 defer allocator.free(term); 796 return self.submit(term); 797 }; 798 return header_view.input(allocator, key, root_focus); 799 } 800 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 801 if (self.detailActive()) { 802 try self.detailInput(allocator, key, root_focus); 803 } else { 804 try self.listInput(allocator, key, root_focus); 805 } 806 } 807 808 // navigate to the typed term's results, pinned to the listing's ref. an 809 // empty term leaves the results for the plain listing. 810 fn submit(self: *View, term: []const u8) !void { 811 if (term.len == 0 and self.data.find == null) return; 812 const route = self.data.filesRoute("", 0) orelse return; 813 try self.session.navigate(route.withFind(term) orelse return); 814 } 815 816 fn listInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 817 // up/down (and the scroll wheel) move the selection; page up/down jump a 818 // fixed amount. right/Enter cross into the detail pane. Enter/clicks on a 819 // directory (or "..") row are turned into navigation by the host 820 // (crossPageLink) before reaching here. 821 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 822 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 823 return; 824 } 825 switch (key) { 826 .enter, .arrow_right => try self.focusDetail(root_focus), 827 // when the window is too narrow to lay out the detail pane beside 828 // the list, a click on a row opens it like enter. the row was just 829 // selected, so the detail is swapped to it ahead of the build. 830 .mouse => |mouse| if (self.contentBox().children.values()[detail_index].rect == null and ui.widget.clickOnSelectedRow(self.listBox(), root_focus, mouse)) { 831 try self.refreshDetail(allocator, true); 832 try self.focusDetail(root_focus); 833 }, 834 else => {}, 835 } 836 } 837 838 // whether focus is on the content box (vs. a "previous"/"next" nav link). 839 fn focusOnContent(self: *View, root_focus: *Focus) bool { 840 const g = root_focus.grandchild_id orelse return false; 841 if (self.markdownView()) |view| return view.owns(g); 842 return self.detailInner().children.contains(g); 843 } 844 845 // the rendered markdown in the detail pane, if that's what it shows 846 fn markdownView(self: *View) ?*Markdown.View { 847 const inner = self.detailInner(); 848 if (inner.children.count() == 0) return null; 849 return switch (inner.children.values()[0].widget) { 850 .markdown => |*view| view, 851 else => null, 852 }; 853 } 854 855 fn detailInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 856 // the way back to the list, by enter or a click 857 if (self.back_id) |id| { 858 if (inp.activated(root_focus, id, key)) return self.focusList(root_focus); 859 } 860 const sc = self.detailScroll(); 861 const on_content = self.focusOnContent(root_focus); 862 // the "next" link sits above the content scroll. on the link, left returns 863 // to the file list and down drops into the content. in the content, the 864 // terminal scrolls by offset (the wheel five rows at a time) and reaching 865 // the top then pressing up crosses back up to the link; on the web 866 // vertical scrolling is the browser's job so up just crosses to the link. 867 const step: isize = switch (key) { 868 .scroll_up, .scroll_down => 5, 869 else => 1, 870 }; 871 switch (inp.vertDirection(key)) { 872 .up => { 873 if (!on_content) return; 874 if (self.session.is_terminal and sc.y > 0) { 875 sc.y -= step; 876 self.detailScroll().clampToContent(); 877 } else self.focusNav(root_focus); 878 return; 879 }, 880 .down => { 881 if (!on_content) return self.focusContent(root_focus); 882 if (self.session.is_terminal) { 883 sc.y += step; 884 self.detailScroll().clampToContent(); 885 } 886 return; 887 }, 888 .none => {}, 889 } 890 switch (key) { 891 .arrow_left => { 892 if (on_content) { 893 if (sc.x > 0) { 894 sc.x -= 1; 895 self.detailScroll().clampToContent(); 896 } else try self.focusList(root_focus); 897 } else if (!self.moveNav(root_focus, -1)) { 898 try self.focusList(root_focus); 899 } 900 }, 901 .arrow_right => { 902 if (on_content) { 903 sc.x += 1; 904 self.detailScroll().clampToContent(); 905 } else _ = self.moveNav(root_focus, 1); 906 }, 907 .page_up => if (on_content and self.session.is_terminal) { 908 sc.y -= 10; 909 self.detailScroll().clampToContent(); 910 }, 911 .page_down => if (on_content and self.session.is_terminal) { 912 sc.y += 10; 913 self.detailScroll().clampToContent(); 914 }, 915 .home => if (on_content and self.session.is_terminal) { 916 sc.y = 0; 917 self.detailScroll().clampToContent(); 918 }, 919 .end => if (on_content and self.session.is_terminal) { 920 sc.y = std.math.maxInt(isize); 921 self.detailScroll().clampToContent(); 922 }, 923 // step between the rendered markdown's links; the web leaves tab to the browser 924 .tab, .back_tab => if (on_content and self.session.is_terminal) if (self.markdownView()) |view| { 925 try view.stepLink(allocator, root_focus, sc, 0, 0, key == .tab); 926 }, 927 else => {}, 928 } 929 } 930 931 // focus the first (left-most) nav link; a no-op when there are none, leaving 932 // focus on the content. 933 fn focusNav(self: *View, root_focus: *Focus) void { 934 const nav_box = self.navBox(); 935 if (nav_box.children.count() == 0) return; 936 root_focus.setFocus(nav_box.children.keys()[0]); 937 } 938 939 fn focusContent(self: *View, root_focus: *Focus) void { 940 if (self.markdownView()) |view| return root_focus.setFocus(view.body.id); 941 const inner = self.detailInner(); 942 const id = inner.getFocus().child_id orelse (if (inner.children.count() > 0) inner.children.keys()[0] else return); 943 root_focus.setFocus(id); 944 } 945 946 // move focus `delta` rows within the nav box; returns false (without moving) 947 // when that would step off either end. 948 fn moveNav(self: *View, root_focus: *Focus, delta: isize) bool { 949 const nav_box = self.navBox(); 950 const keys = nav_box.children.keys(); 951 const cur_id = nav_box.getFocus().child_id orelse return false; 952 const cur: isize = @intCast(nav_box.children.getIndex(cur_id) orelse return false); 953 const target = cur + delta; 954 if (target < 0 or target >= @as(isize, @intCast(keys.len))) return false; 955 root_focus.setFocus(keys[@intCast(target)]); 956 return true; 957 } 958 959 // enter the detail pane, landing on the "next" link when there is one (so 960 // right-arrow reaches it), else on the content. a directory or ".." row has 961 // neither, so there's nothing to enter. selecting the frame's child (then 962 // focusing the frame) also handles the too-narrow case where the pane isn't 963 // laid out yet — focus lands inside it after the next build. 964 fn focusDetail(self: *View, root_focus: *Focus) !void { 965 const frame = self.detailOuter(); 966 if (self.navBox().children.count() > 0) { 967 frame.getFocus().child_id = self.navBox().getFocus().id; 968 } else if (self.detailInner().children.count() > 0) { 969 frame.getFocus().child_id = self.detailScrollFrame().getFocus().id; 970 } else return; 971 root_focus.setFocus(frame.getFocus().id); 972 } 973 974 // return to the list. 975 fn focusList(self: *View, root_focus: *Focus) !void { 976 root_focus.setFocus(self.listScroll().getFocus().id); 977 } 978 979 pub fn clearGrid(self: *View) void { 980 self.box.clearGrid(); 981 } 982 983 pub fn getGrid(self: View) ?Grid { 984 return self.box.getGrid(); 985 } 986 987 pub fn getFocus(self: *View) *Focus { 988 return self.box.getFocus(); 989 } 990 991 fn contentAtTop(self: *View) bool { 992 if (self.detailActive()) { 993 if (self.detailOuter().getFocus().child_id == self.navBox().getFocus().id) return true; 994 return self.navBox().children.count() == 0 and 995 (!self.session.is_terminal or self.detailScroll().y == 0); 996 } 997 const lb = self.listBox(); 998 const cid = lb.getFocus().child_id orelse return true; 999 return lb.children.getIndex(cid) == 0; 1000 } 1001 1002 // only the header's own row sits directly below the repository header. 1003 pub fn atTop(self: *View) bool { 1004 if (self.data.no_commits or self.data.isEmpty()) return true; 1005 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 1006 return self.headerActive() or (!focusable and self.contentAtTop()); 1007 } 1008 1009 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 1010 const header_view = self.header() orelse return false; 1011 return header_view.focusHeader(root_focus); 1012 } 1013 }; 1014 1015 // `lines` as spans, each prefixed with its 1-based file line number 1016 // (right-aligned in a column wide enough for the last number, then a space), 1017 // like the diffs view. each number links to the window starting at its line. 1018 // `start` is the window's 0-based first line, so numbers continue across 1019 // paginated windows. 1020 fn numberedContent(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8, lines: []const []const u8, start: usize) ![]const wgt.Span { 1021 const arena = page_arena.allocator(); 1022 const width = std.fmt.count("{d}", .{start + lines.len}); 1023 var spans: std.ArrayList(wgt.Span) = .empty; 1024 for (lines, 0..) |line, i| { 1025 const number = start + i + 1; 1026 const route = data.filesRoute(path, number) orelse return error.RouteTooLong; 1027 try spans.append(arena, .{ .text = try arena.print("{d: >[1]}", .{ number, width }), .link = try route.toUrl(page_arena) }); 1028 try spans.append(arena, .{ .text = try arena.print(" {s}{s}", .{ line, if (i + 1 < lines.len) "\n" else "" }) }); 1029 } 1030 return spans.toOwnedSlice(arena); 1031 } 1032 1033 // the index of the "README"/"README.md" file entry (case-insensitive), or null 1034 // if none. used to pick the default selection at the repo root. 1035 fn readmeIndex(entries: []const Entry) ?usize { 1036 for (entries, 0..) |entry, i| { 1037 if (!entry.is_dir and isReadme(entry.name)) return i; 1038 } 1039 return null; 1040 } 1041 1042 fn isMarkdown(name: []const u8) bool { 1043 const extension = std.Io.Dir.path.extension(name); 1044 return std.ascii.eqlIgnoreCase(extension, ".md") or std.ascii.eqlIgnoreCase(extension, ".markdown"); 1045 } 1046 1047 fn isReadme(name: []const u8) bool { 1048 return std.ascii.eqlIgnoreCase(name, "README") or std.ascii.eqlIgnoreCase(name, "README.md"); 1049 } 1050 1051 // the index of the entry the route named (data.selected_file), or null if none. 1052 fn selectedFileIndex(data: *const Self) ?usize { 1053 const name = data.selected_file orelse return null; 1054 for (data.entries, 0..) |entry, i| { 1055 if (!entry.is_dir and std.mem.eql(u8, entry.name, name)) return i; 1056 } 1057 return null; 1058 } 1059 1060 // an "a:" link to the files route at `path`, pinned to the listing's ref, so 1061 // following it navigates to that directory's listing. 1062 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 1063 const route = data.filesRoute(path, 0) orelse return error.RouteTooLong; 1064 return page_arena.allocator().print("a:{s}", .{try route.toUrl(page_arena)}); 1065 } 1066 1067 // a link to the file's route. a preloaded file gets an "ai:" link 1068 // (crossPageLink ignores it, so a click selects the row in place and shows its 1069 // contents); an unloaded file gets an "a:" link, so activating it reloads the 1070 // page with that file selected and its content read. 1071 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8, loaded: bool, line: usize) ![]const u8 { 1072 const route = data.filesRoute(path, line) orelse return error.RouteTooLong; 1073 const prefix = if (loaded) "ai:" else "a:"; 1074 return page_arena.allocator().print("{s}{s}", .{ prefix, try route.toUrl(page_arena) }); 1075 } 1076 1077 // the url `line` value for a content window: its first line's 1-based number, 1078 // except the first window, which serializes as unset (0). 1079 fn lineNumber(window_start: usize) usize { 1080 return if (window_start == 0) 0 else window_start + 1; 1081 } 1082 1083 // `dir`/`name`, or just `name` at the root. 1084 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 1085 return if (dir.len == 0) name else arena.print("{s}/{s}", .{ dir, name }); 1086 } 1087 1088 // `dir` with its last segment removed ("" when `dir` has a single segment). 1089 fn parentDir(dir: []const u8) []const u8 { 1090 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 1091 return dir[0..slash]; 1092 } 1093 1094 // a search result's bottom label: the directory it sits in, empty at the root. 1095 // a directory too wide for the list column is clipped from the left. 1096 fn resultDirLabel(aa: std.mem.Allocator, path: []const u8) ![]const u8 { 1097 const slash = std.mem.lastIndexOfScalar(u8, path, '/') orelse return ""; 1098 const dir = path[0..slash]; 1099 // the row's border and the label's padding take two columns each 1100 const max_width = View.list_max_width - 4; 1101 var width = try xitui.width.displayWidth(dir); 1102 if (width <= max_width) return aa.print(" {s} ", .{dir}); 1103 1104 const ellipsis = ".."; 1105 var iter = (try std.unicode.Utf8View.init(dir)).iterator(); 1106 var start: usize = 0; 1107 while (width > max_width - ellipsis.len) { 1108 const slice = iter.nextCodepointSlice() orelse break; 1109 width -= xitui.width.cellWidth(try std.unicode.utf8Decode(slice)); 1110 start += slice.len; 1111 } 1112 return aa.print(" " ++ ellipsis ++ "{s} ", .{dir[start..]}); 1113 } 1114