aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/crash/dir.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/crash/dir.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/crash/dir.zig')
-rw-r--r--vendor/libghostty-vt/src/crash/dir.zig66
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/crash/dir.zig b/vendor/libghostty-vt/src/crash/dir.zig
new file mode 100644
index 00000000..e5a8f8a0
--- /dev/null
+++ b/vendor/libghostty-vt/src/crash/dir.zig
@@ -0,0 +1,66 @@
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const internal_os = @import("../os/main.zig");
+
+/// Returns a Dir for the default directory. The Dir.path field must be
+/// freed with the given allocator.
+pub fn defaultDir(alloc: Allocator) !Dir {
+ const crash_dir = try internal_os.xdg.state(alloc, .{ .subdir = "ghostty/crash" });
+ errdefer alloc.free(crash_dir);
+ return .{ .path = crash_dir };
+}
+
+pub const Dir = struct {
+ /// The directory where crash reports are stored. This memory is owned
+ /// by the caller.
+ path: []const u8,
+
+ /// Returns an iterator over the crash reports in this directory. This
+ /// iterator must be freed with `ReportIterator.deinit`. The iterator
+ /// may have no reports.
+ pub fn iterator(self: *const Dir) !ReportIterator {
+ var dir = std.fs.openDirAbsolute(
+ self.path,
+ .{ .iterate = true },
+ ) catch return .{};
+ errdefer dir.close();
+
+ return .{
+ .dir = dir,
+ .it = dir.iterate(),
+ };
+ }
+};
+
+pub const ReportIterator = struct {
+ dir: ?std.fs.Dir = null,
+ it: std.fs.Dir.Iterator = undefined,
+
+ pub fn deinit(self: *ReportIterator) void {
+ if (self.dir) |dir| dir.close();
+ }
+
+ pub fn next(self: *ReportIterator) !?Report {
+ // If we have no dir then we failed to open the directory.
+ const dir = self.dir orelse return null;
+
+ // Get the next file entry, if any.
+ const entry = entry: while (true) {
+ const entry = try self.it.next() orelse return null;
+ if (entry.kind != .file) continue;
+ break :entry entry;
+ };
+
+ const stat = try dir.statFile(entry.name);
+ return .{
+ .name = entry.name,
+ .mtime = stat.mtime,
+ };
+ }
+};
+
+pub const Report = struct {
+ name: []const u8,
+ mtime: i128,
+};