╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1069 // `dir` with its last segment removed ("" when `dir` has a single segment). 1070 fn parentDir(dir: []const u8) []const u8 { 1071 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 1072 return dir[0..slash]; 1073 } 1074 1075 // a search result's bottom label: the directory it sits in, empty at the root. 1076 // a directory too wide for the list column is clipped from the left. 1077 fn resultDirLabel(aa: std.mem.Allocator, path: []const u8) ![]const u8 { 1078 const slash = std.mem.lastIndexOfScalar(u8, path, '/') orelse return ""; 1079 const dir = path[0..slash]; 1080 // the row's border and the label's padding take two columns each 1081 const max_width = View.list_max_width - 4; 1082 var width = try xitui.width.displayWidth(dir); 1083 if (width <= max_width) return aa.print(" {s} ", .{dir}); 1084 1085 const ellipsis = ".."; 1086 var iter = (try std.unicode.Utf8View.init(dir)).iterator(); 1087 var start: usize = 0; 1088 while (width > max_width - ellipsis.len) { 1089 const slice = iter.nextCodepointSlice() orelse break; 1090 width -= xitui.width.cellWidth(try std.unicode.utf8Decode(slice)); 1091 start += slice.len; 1092 } 1093 return aa.print(" " ++ ellipsis ++ "{s} ", .{dir[start..]}); 1094 } 1095