╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
835 // the index of the entry the route named (data.selected_file), or null if none. 836 fn selectedFileIndex(data: *const Self) ?usize { 837 const name = data.selected_file orelse return null; 838 for (data.entries, 0..) |entry, i| { 839 if (!entry.is_dir and std.mem.eql(u8, entry.name, name)) return i; 840 } 841 return null; 842 } 843 844 // an "a:" link to the files route at `path`, pinned to the listing's ref, so 845 // following it navigates to that directory's listing. 846 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 847 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 848 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{try route.urlAlloc(page_arena)}); 849 } 850 851 // an "ai:" link to the file's route: crossPageLink ignores it, so a wasm click 852 // selects the row in place and shows its contents in the detail pane. 853 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8) ![]const u8 { 854 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 855 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.urlAlloc(page_arena)}); 856 } 857 858 // `dir`/`name`, or just `name` at the root. 859 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 860 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 861 } 862 863 // `dir` with its last segment removed ("" when `dir` has a single segment). 864 fn parentDir(dir: []const u8) []const u8 { 865 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 866 return dir[0..slash]; 867 } 868