diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/pkg/macos/os/log.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/pkg/macos/os/log.zig')
| -rw-r--r-- | vendor/libghostty-vt/pkg/macos/os/log.zig | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/macos/os/log.zig b/vendor/libghostty-vt/pkg/macos/os/log.zig new file mode 100644 index 00000000..219c914d --- /dev/null +++ b/vendor/libghostty-vt/pkg/macos/os/log.zig @@ -0,0 +1,65 @@ +const std = @import("std"); +const assert = std.debug.assert; +const Allocator = std.mem.Allocator; +const c = @import("c.zig").c; + +pub const Log = opaque { + pub fn create( + subsystem: [:0]const u8, + category: [:0]const u8, + ) *Log { + return @ptrCast(c.os_log_create( + subsystem.ptr, + category.ptr, + ).?); + } + + pub fn release(self: *Log) void { + c.os_release(self); + } + + pub fn typeEnabled(self: *Log, typ: LogType) bool { + return c.os_log_type_enabled( + @ptrCast(self), + @intFromEnum(typ), + ); + } + + pub fn log( + self: *Log, + alloc: Allocator, + typ: LogType, + comptime format: []const u8, + args: anytype, + ) void { + const str = nosuspend std.fmt.allocPrintSentinel( + alloc, + format, + args, + 0, + ) catch return; + defer alloc.free(str); + zig_os_log_with_type(self, typ, str.ptr); + } + + extern "c" fn zig_os_log_with_type(*Log, LogType, [*c]const u8) void; +}; + +/// https://developer.apple.com/documentation/os/os_log_type_t?language=objc +pub const LogType = enum(c.os_log_type_t) { + default = c.OS_LOG_TYPE_DEFAULT, + debug = c.OS_LOG_TYPE_DEBUG, + info = c.OS_LOG_TYPE_INFO, + err = c.OS_LOG_TYPE_ERROR, + fault = c.OS_LOG_TYPE_FAULT, +}; + +test { + const testing = std.testing; + + const log = Log.create("com.mitchellh.ghostty", "test"); + defer log.release(); + + try testing.expect(log.typeEnabled(.fault)); + log.log(testing.allocator, .default, "hello {d}", .{12}); +} |
