From 84b1ae9a3c53c14babd0b6687a7d0aee2ab6f1e7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Nov 2022 10:20:18 -0800 Subject: [PATCH] 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. --- src/Pty.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Pty.zig b/src/Pty.zig index b2c7580de..a09b2519e 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -55,6 +55,19 @@ pub fn open(size: winsize) !Pty { @ptrCast([*c]c.struct_winsize, &sizeCopy), ) < 0) 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{ .master = master_fd,