Add file and project search panels
This commit is contained in:
+16
-4
@@ -192,10 +192,22 @@ fn openDirectoryPreview(allocator: std.mem.Allocator, io: std.Io, client: *tui.C
|
||||
while (try iterator.next(io)) |entry| {
|
||||
if (count >= 80) break;
|
||||
if (entry.kind != .file and entry.kind != .directory) continue;
|
||||
const suffix = if (entry.kind == .directory) "/" else "";
|
||||
const command = try std.fmt.allocPrint(allocator, "repo_file {s}{s}=", .{ entry.name, suffix });
|
||||
defer allocator.free(command);
|
||||
client.handleTraceLine(command) catch {};
|
||||
const relative_path = try std.fmt.allocPrint(allocator, "{s}/{s}{s}", .{ path, entry.name, if (entry.kind == .directory) "/" else "" });
|
||||
defer allocator.free(relative_path);
|
||||
if (entry.kind == .file) {
|
||||
const bytes = std.Io.Dir.cwd().readFileAlloc(io, relative_path, allocator, .limited(diagnostics.max_file_bytes)) catch |err| switch (err) {
|
||||
error.StreamTooLong, error.AccessDenied, error.FileNotFound, error.NotDir => null,
|
||||
else => null,
|
||||
};
|
||||
if (bytes) |content| {
|
||||
defer allocator.free(content);
|
||||
client.addRepoFileContent(relative_path, content) catch {};
|
||||
} else {
|
||||
client.addRepoFileContent(relative_path, "") catch {};
|
||||
}
|
||||
} else {
|
||||
client.addRepoFileContent(relative_path, "") catch {};
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
try client.handleTraceLine("file_picker");
|
||||
|
||||
Reference in New Issue
Block a user