mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
compilation for macos works?
This commit is contained in:
15
src/Pty.zig
15
src/Pty.zig
@ -4,13 +4,19 @@
|
||||
const Pty = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const testing = std.testing;
|
||||
const linux = std.os.linux;
|
||||
const fd_t = std.os.fd_t;
|
||||
const winsize = linux.winsize;
|
||||
const c = @cImport({
|
||||
const c = switch (builtin.os.tag) {
|
||||
.macos => @cImport({
|
||||
@cInclude("util.h");
|
||||
}),
|
||||
else => @cImport({
|
||||
@cInclude("pty.h");
|
||||
});
|
||||
}),
|
||||
};
|
||||
|
||||
/// The file descriptors for the master and slave side of the pty.
|
||||
master: fd_t,
|
||||
@ -18,6 +24,9 @@ slave: fd_t,
|
||||
|
||||
/// Open a new PTY with the given initial size.
|
||||
pub fn open(size: winsize) !Pty {
|
||||
// Need to copy so that it becomes non-const.
|
||||
var sizeCopy = size;
|
||||
|
||||
var master_fd: fd_t = undefined;
|
||||
var slave_fd: fd_t = undefined;
|
||||
if (c.openpty(
|
||||
@ -25,7 +34,7 @@ pub fn open(size: winsize) !Pty {
|
||||
&slave_fd,
|
||||
null,
|
||||
null,
|
||||
@ptrCast([*c]const c.struct_winsize, &size),
|
||||
@ptrCast([*c]c.struct_winsize, &sizeCopy),
|
||||
) < 0)
|
||||
return error.OpenptyFailed;
|
||||
|
||||
|
@ -103,14 +103,16 @@ fn threadMain(self: *Embed) void {
|
||||
|
||||
// kqueue
|
||||
.macos, .dragonfly, .freebsd, .openbsd, .netbsd => {
|
||||
// TODO: untested, probably some compile errors here
|
||||
// or other issues, but this is roughly what we're trying
|
||||
// to do.
|
||||
var ts: std.os.timespec = .{
|
||||
.tv_sec = timeout / 1000,
|
||||
.tv_nsec = (timeout % 1000) * 1000,
|
||||
.tv_sec = @divTrunc(timeout, 1000),
|
||||
.tv_nsec = @mod(timeout, 1000) * 1000,
|
||||
};
|
||||
|
||||
var ev: [0]std.os.Kevent = undefined;
|
||||
_ = std.os.kevent(fd, &ev, &ev, &ts) catch |err| blk: {
|
||||
log.err("kevent error: {}", .{err});
|
||||
break :blk 0;
|
||||
};
|
||||
while ((try std.os.kevent(fd, null, null, &ts)) == -1) {}
|
||||
},
|
||||
|
||||
else => @compileError("unsupported libuv Embed platform"),
|
||||
|
Reference in New Issue
Block a user