╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
263 pub fn getFocus(self: *View) *Focus { 264 return self.box.getFocus(); 265 } 266 267 pub fn getSelectedIndex(self: *View) ?usize { 268 const box = self.innerBox(); 269 const child_id = box.focus.child_id orelse return null; 270 return box.children.getIndex(child_id); 271 } 272 }; 273 274 // the "a:" link for the files route at `dir`, pinned to the listing's ref. 275 fn dirLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, dir: []const u8) ![]const u8 { 276 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, dir) orelse return error.RouteTooLong; 277 const url = try route.urlAlloc(page_arena); 278 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 279 } 280 281 // `dir`/`name`, or just `name` at the root. 282 fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 283 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 284 } 285 286 // `dir` with its last segment removed ("" when `dir` has a single segment). 287 fn parentDir(dir: []const u8) []const u8 { 288 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 289 return dir[0..slash]; 290 } 291