╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1021 1022 // the url `line` value for a content window: its first line's 1-based number, 1023 // except the first window, which serializes as unset (0). 1024 fn lineNumber(window_start: usize) usize { 1025 return if (window_start == 0) 0 else window_start + 1; 1026 } 1027 1028 // `dir`/`name`, or just `name` at the root. 1029 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 1030 return if (dir.len == 0) name else arena.print("{s}/{s}", .{ dir, name }); 1031 } 1032 1033 // `dir` with its last segment removed ("" when `dir` has a single segment). 1034 fn parentDir(dir: []const u8) []const u8 { 1035 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 1036 return dir[0..slash]; 1037 } 1038 1039 // a search result's bottom label: the directory it sits in, empty at the root. 1040 // a directory too wide for the list column is clipped from the left. 1041 fn resultDirLabel(aa: std.mem.Allocator, path: []const u8) ![]const u8 { 1042 const slash = std.mem.lastIndexOfScalar(u8, path, '/') orelse return ""; 1043 const dir = path[0..slash]; 1044 // the row's border and the label's padding take two columns each 1045 const max_width = View.list_max_width - 4; 1046 var width = try xitui.width.displayWidth(dir); 1047 if (width <= max_width) return aa.print(" {s} ", .{dir}); 1048 1049 const ellipsis = ".."; 1050 var iter = (try std.unicode.Utf8View.init(dir)).iterator(); 1051 var start: usize = 0; 1052 while (width > max_width - ellipsis.len) { 1053 const slice = iter.nextCodepointSlice() orelse break; 1054 width -= xitui.width.cellWidth(try std.unicode.utf8Decode(slice)); 1055 start += slice.len; 1056 } 1057 return aa.print(" " ++ ellipsis ++ "{s} ", .{dir[start..]}); 1058 } 1059