╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
827 for (entries, 0..) |entry, i| { 828 if (entry.is_dir) continue; 829 if (std.ascii.eqlIgnoreCase(entry.name, "README") or std.ascii.eqlIgnoreCase(entry.name, "README.md")) 830 return i; 831 } 832 return null; 833 } 834 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 // the "a:" link for the files route at `dir`, pinned to the listing's ref. 845 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, dir: []const u8) ![]const u8 { 846 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, dir, 0) orelse return error.RouteTooLong; 847 const url = try route.urlAlloc(page_arena); 848 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 849 } 850 851 // `dir`/`name`, or just `name` at the root. 852 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 853 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 854 } 855 856 // `dir` with its last segment removed ("" when `dir` has a single segment). 857 fn parentDir(dir: []const u8) []const u8 { 858 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 859 return dir[0..slash]; 860 } 861