set IUTF8 on the pty

This is important on Mac since the pty by default on Mac does NOT have
this enabled. Without this, attempting to read/write UTF-8 characters
in the raw pty layer would sometimes turn into '?' even though ghostty
fully supports it.
This commit is contained in:
Mitchell Hashimoto
2022-11-24 10:20:18 -08:00
parent 70b017200a
commit 84b1ae9a3c

View File

@ -55,6 +55,19 @@ pub fn open(size: winsize) !Pty {
@ptrCast([*c]c.struct_winsize, &sizeCopy), @ptrCast([*c]c.struct_winsize, &sizeCopy),
) < 0) ) < 0)
return error.OpenptyFailed; return error.OpenptyFailed;
errdefer {
_ = std.os.system.close(master_fd);
_ = std.os.system.close(slave_fd);
}
// Enable UTF-8 mode. I think this is on by default on Linux but it
// is NOT on by default on macOS so we ensure that it is always set.
var attrs: c.termios = undefined;
if (c.tcgetattr(master_fd, &attrs) != 0)
return error.OpenptyFailed;
attrs.c_iflag |= c.IUTF8;
if (c.tcsetattr(master_fd, c.TCSANOW, &attrs) != 0)
return error.OpenptyFailed;
return Pty{ return Pty{
.master = master_fd, .master = master_fd,