╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
806 try out.appendSlice(arena, line); 807 } 808 return out.toOwnedSlice(arena); 809 } 810 811 // the index of the "README"/"README.md" file entry (case-insensitive), or null 812 // if none. used to pick the default selection at the repo root. 813 fn readmeIndex(entries: []const Entry) ?usize { 814 for (entries, 0..) |entry, i| { 815 if (entry.is_dir) continue; 816 if (std.ascii.eqlIgnoreCase(entry.name, "README") or std.ascii.eqlIgnoreCase(entry.name, "README.md")) 817 return i; 818 } 819 return null; 820 } 821 822 // the index of the entry the route named (data.selected_file), or null if none. 823 fn selectedFileIndex(data: *const Self) ?usize { 824 const name = data.selected_file orelse return null; 825 for (data.entries, 0..) |entry, i| { 826 if (!entry.is_dir and std.mem.eql(u8, entry.name, name)) return i; 827 } 828 return null; 829 } 830 831 // an "a:" link to the files route at `path`, pinned to the listing's ref, so 832 // following it navigates to that directory's listing. 833 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 834 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 835 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.urlAlloc(page_arena)}); 836 } 837 838 // an "ai:" link to the file's route: crossPageLink ignores it, so a wasm click 839 // selects the row in place and shows its contents in the detail pane. 840 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 841 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 842 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.urlAlloc(page_arena)}); 843 } 844 845 // `dir`/`name`, or just `name` at the root. 846 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 847 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 848 } 849 850 // `dir` with its last segment removed ("" when `dir` has a single segment). 851 fn parentDir(dir: []const u8) []const u8 { 852 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 853 return dir[0..slash]; 854 } 855