╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
1082 1083 // `dir`/`name`, or just `name` at the root. 1084 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 1085 return if (dir.len == 0) name else arena.print("{s}/{s}", .{ dir, name }); 1086 } 1087 1088 // `dir` with its last segment removed ("" when `dir` has a single segment). 1089 fn parentDir(dir: []const u8) []const u8 { 1090 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 1091 return dir[0..slash]; 1092 } 1093 1094 // a search result's bottom label: the directory it sits in, empty at the root. 1095 // a directory too wide for the list column is clipped from the left. 1096 fn resultDirLabel(aa: std.mem.Allocator, path: []const u8) ![]const u8 { 1097 const slash = std.mem.lastIndexOfScalar(u8, path, '/') orelse return ""; 1098 const dir = path[0..slash]; 1099 // the row's border and the label's padding take two columns each 1100 const max_width = View.list_max_width - 4; 1101 var width = try xitui.width.displayWidth(dir); 1102 if (width <= max_width) return aa.print(" {s} ", .{dir}); 1103 1104 const ellipsis = ".."; 1105 var iter = (try std.unicode.Utf8View.init(dir)).iterator(); 1106 var start: usize = 0; 1107 while (width > max_width - ellipsis.len) { 1108 const slice = iter.nextCodepointSlice() orelse break; 1109 width -= xitui.width.cellWidth(try std.unicode.utf8Decode(slice)); 1110 start += slice.len; 1111 } 1112 return aa.print(" " ++ ellipsis ++ "{s} ", .{dir[start..]}); 1113 } 1114