╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
969 } 970 971 // `dir` with its last segment removed ("" when `dir` has a single segment). 972 fn parentDir(dir: []const u8) []const u8 { 973 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 974 return dir[0..slash]; 975 } 976 977 // a search result's bottom label: the directory it sits in, empty at the root. 978 // a directory too wide for the list column is clipped from the left. 979 fn resultDirLabel(aa: std.mem.Allocator, path: []const u8) ![]const u8 { 980 const slash = std.mem.lastIndexOfScalar(u8, path, '/') orelse return ""; 981 const dir = path[0..slash]; 982 // the row's border and the label's padding take two columns each 983 const max_width = View.list_max_width - 4; 984 var width = try xitui.width.displayWidth(dir); 985 if (width <= max_width) return std.fmt.allocPrint(aa, " {s} ", .{dir}); 986 987 const ellipsis = ".."; 988 var iter = (try std.unicode.Utf8View.init(dir)).iterator(); 989 var start: usize = 0; 990 while (width > max_width - ellipsis.len) { 991 const slice = iter.nextCodepointSlice() orelse break; 992 width -= xitui.width.cellWidth(try std.unicode.utf8Decode(slice)); 993 start += slice.len; 994 } 995 return std.fmt.allocPrint(aa, " " ++ ellipsis ++ "{s} ", .{dir[start..]}); 996 } 997