wip: macos
This commit is contained in:
parent
7b7b84ad21
commit
36a276a10b
4 changed files with 30 additions and 18 deletions
|
@ -49,6 +49,7 @@ pub fn main() !void {
|
|||
};
|
||||
const shell = env.get("SHELL") orelse "bash";
|
||||
const argv = [_][]const u8{shell};
|
||||
std.debug.print("executing: {s}\n", .{shell});
|
||||
var vt = try vaxis.widgets.Terminal.init(
|
||||
alloc,
|
||||
&argv,
|
||||
|
@ -62,7 +63,6 @@ pub fn main() !void {
|
|||
var redraw: bool = false;
|
||||
while (true) {
|
||||
std.debug.print("inside while loop before resize\n", .{});
|
||||
std.time.sleep(8 * std.time.ns_per_ms);
|
||||
// try vt events first
|
||||
while (vt.tryEvent()) |event| {
|
||||
std.debug.print("inside stryEventloop \n", .{});
|
||||
|
|
|
@ -20,12 +20,13 @@ pty: Pty,
|
|||
const TIOCSCTTY = if (builtin.os.tag == .macos) 536900705 else c.TIOCSCTTY;
|
||||
const TIOCSWINSZ = if (builtin.os.tag == .macos) 2148037735 else c.TIOCSWINSZ;
|
||||
const TIOCGWINSZ = if (builtin.os.tag == .macos) 1074295912 else c.TIOCGWINSZ;
|
||||
extern "c" fn setsid() std.c.pid_t;
|
||||
// extern "c" fn setsid() std.c.pid_t;
|
||||
const c = struct {
|
||||
usingnamespace switch (builtin.os.tag) {
|
||||
.macos => @cImport({
|
||||
@cInclude("sys/ioctl.h"); // ioctl and constants
|
||||
@cInclude("util.h"); // openpty()
|
||||
@cInclude("util.h");
|
||||
@cInclude("unistd.h"); // openpty()
|
||||
}),
|
||||
else => @cImport({
|
||||
@cInclude("sys/ioctl.h"); // ioctl and constants
|
||||
|
@ -47,15 +48,27 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
|
|||
|
||||
const pid = try std.posix.fork();
|
||||
if (pid == 0) {
|
||||
// we are the child
|
||||
_ = std.os.linux.setsid();
|
||||
_ = setsid();
|
||||
// if (setsid() < 0) return error.ProcessGroupFailed;
|
||||
|
||||
// set the controlling terminal
|
||||
std.posix.close(self.pty.pty);
|
||||
std.debug.print("inside child\n", .{});
|
||||
if (c.setsid() != 0) return error.SetSid;
|
||||
std.debug.print("setting up io for tty\n", .{});
|
||||
var u: c_uint = std.posix.STDIN_FILENO;
|
||||
|
||||
if (c.ioctl(self.pty.tty, TIOCSCTTY, @intFromPtr(&u)) != 0) return error.IoctlError;
|
||||
|
||||
// switch (builtin.os.tag) {
|
||||
// .linux => {},
|
||||
// .ios, .macos => {
|
||||
// // Mac doesn't support dup3 so we use dup2. We purposely clear
|
||||
// // CLO_ON_EXEC for this fd.
|
||||
// const flags = try posix.fcntl(self.pty.tty, posix.F.GETFD, 0);
|
||||
// if (flags & posix.FD_CLOEXEC != 0) {
|
||||
// _ = try posix.fcntl(self.pty.tty, posix.F.SETFD, flags & ~@as(u32, posix.FD_CLOEXEC));
|
||||
// }
|
||||
// },
|
||||
// else => @compileError("unsupported platform"),
|
||||
// }
|
||||
|
||||
// set up io
|
||||
try posix.dup2(self.pty.tty, std.posix.STDIN_FILENO);
|
||||
try posix.dup2(self.pty.tty, std.posix.STDOUT_FILENO);
|
||||
|
@ -69,17 +82,17 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
|
|||
}
|
||||
|
||||
// exec
|
||||
const err = std.posix.execvpeZ(argv_buf.ptr[0].?, argv_buf.ptr, envp);
|
||||
_ = err catch {};
|
||||
} else {
|
||||
std.debug.print("we are not child: {d}\n", .{pid});
|
||||
// posix.close(self.pty.tty);
|
||||
_ = posix.waitpid(pid, 0);
|
||||
_ = std.posix.execvpeZ(argv_buf.ptr[0].?, argv_buf.ptr, envp) catch null;
|
||||
|
||||
//return error.ExecFailed;
|
||||
// const err = std.posix.execvpeZ("/bin/zsh", "/bin/zsh", envp);
|
||||
// _ = err catch {};
|
||||
}
|
||||
|
||||
// we are the parent
|
||||
self.pid = @intCast(pid);
|
||||
|
||||
_ = posix.waitpid(pid, 0);
|
||||
std.debug.print("waitpid in parent\n", .{});
|
||||
if (!Terminal.global_sigchild_installed) {
|
||||
Terminal.global_sigchild_installed = true;
|
||||
var act = posix.Sigaction{
|
||||
|
|
|
@ -33,7 +33,7 @@ tty: posix.fd_t,
|
|||
pub fn init() !Pty {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => return openPtyLinux(),
|
||||
.macos => return openPtyMacos2(),
|
||||
.macos => return openPtyMacos(),
|
||||
else => @compileError("unsupported os"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,6 @@ pub fn init(
|
|||
unicode: *const vaxis.Unicode,
|
||||
opts: Options,
|
||||
) !Terminal {
|
||||
// Verify we have an absolute path
|
||||
if (opts.initial_working_directory) |pwd| {
|
||||
if (!std.fs.path.isAbsolute(pwd)) return error.InvalidWorkingDirectory;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue