aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/pty.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/pty.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/pty.zig')
-rw-r--r--vendor/libghostty-vt/src/pty.zig79
1 files changed, 46 insertions, 33 deletions
diff --git a/vendor/libghostty-vt/src/pty.zig b/vendor/libghostty-vt/src/pty.zig
index 40277a8b..de42ef57 100644
--- a/vendor/libghostty-vt/src/pty.zig
+++ b/vendor/libghostty-vt/src/pty.zig
@@ -153,19 +153,20 @@ const PosixPty = struct {
// Set CLOEXEC on the master fd, only the slave fd should be inherited
// by the child process (shell/command).
cloexec: {
- const flags = posix.fcntl(master_fd, posix.F.GETFD, 0) catch |err| {
- log.warn("error getting flags for master fd err={}", .{err});
+ const flags = posix.system.fcntl(master_fd, posix.F.GETFD);
+ if (flags == -1) {
+ log.warn("error getting flags for master fd err=E{s}", .{@tagName(posix.errno(-1))});
break :cloexec;
- };
+ }
- _ = posix.fcntl(
+ switch (posix.errno(posix.system.fcntl(
master_fd,
posix.F.SETFD,
flags | posix.FD_CLOEXEC,
- ) catch |err| {
- log.warn("error setting CLOEXEC on master fd err={}", .{err});
- break :cloexec;
- };
+ ))) {
+ .SUCCESS => {},
+ else => |e| log.warn("error setting CLOEXEC on master fd err=E{}", .{e}),
+ }
}
// Enable UTF-8 mode. I think this is on by default on Linux but it
@@ -260,8 +261,8 @@ const PosixPty = struct {
}
// Can close master/slave pair now
- posix.close(self.slave);
- posix.close(self.master);
+ _ = posix.system.close(self.slave);
+ _ = posix.system.close(self.master);
}
/// Get information about the process(es) attached to the PTY. Returns
@@ -275,9 +276,9 @@ const PosixPty = struct {
const linux = std.os.linux;
var pgrp: i32 = undefined;
const rc = linux.tcgetpgrp(self.master, &pgrp);
- switch (linux.E.init(rc)) {
- .SUCCESS => return @intCast(pgrp),
- else => return null,
+ switch (rc) {
+ 0 => return @intCast(pgrp), // SUCCESS
+ else => return null, // Anything else
}
},
else => {
@@ -334,7 +335,7 @@ const WindowsPty = struct {
in_pipe: windows.HANDLE,
out_pipe_pty: windows.HANDLE,
in_pipe_pty: windows.HANDLE,
- pseudo_console: windows.exp.HPCON,
+ pseudo_console: windows.HPCON,
size: winsize,
pub const OpenError = error{Unexpected};
@@ -367,10 +368,10 @@ const WindowsPty = struct {
.lpSecurityDescriptor = null,
};
- pty.in_pipe = windows.kernel32.CreateNamedPipeW(
+ pty.in_pipe = windows.exp.kernel32.CreateNamedPipeW(
pipe_path_w.ptr,
windows.PIPE_ACCESS_OUTBOUND |
- windows.exp.FILE_FLAG_FIRST_PIPE_INSTANCE |
+ windows.FILE_FLAG_FIRST_PIPE_INSTANCE |
windows.FILE_FLAG_OVERLAPPED,
windows.PIPE_TYPE_BYTE,
1,
@@ -380,12 +381,12 @@ const WindowsPty = struct {
&security_attributes,
);
if (pty.in_pipe == windows.INVALID_HANDLE_VALUE) {
- return windows.unexpectedError(windows.kernel32.GetLastError());
+ return windows.unexpectedError(windows.GetLastError());
}
- errdefer _ = windows.CloseHandle(pty.in_pipe);
+ errdefer _ = windows.exp.kernel32.CloseHandle(pty.in_pipe);
var security_attributes_read = security_attributes;
- pty.in_pipe_pty = windows.kernel32.CreateFileW(
+ pty.in_pipe_pty = windows.exp.kernel32.CreateFileW(
pipe_path_w.ptr,
windows.GENERIC_READ,
0,
@@ -395,9 +396,9 @@ const WindowsPty = struct {
null,
);
if (pty.in_pipe_pty == windows.INVALID_HANDLE_VALUE) {
- return windows.unexpectedError(windows.kernel32.GetLastError());
+ return windows.unexpectedError(windows.GetLastError());
}
- errdefer _ = windows.CloseHandle(pty.in_pipe_pty);
+ errdefer _ = windows.exp.kernel32.CloseHandle(pty.in_pipe_pty);
// The in_pipe needs to be created as a named pipe, since anonymous
// pipes created with CreatePipe do not support overlapped operations,
@@ -414,18 +415,30 @@ const WindowsPty = struct {
// _ = windows.CloseHandle(pty.in_pipe);
// }
- if (windows.exp.kernel32.CreatePipe(&pty.out_pipe, &pty.out_pipe_pty, null, 0) == 0) {
- return windows.unexpectedError(windows.kernel32.GetLastError());
+ if (windows.exp.kernel32.CreatePipe(&pty.out_pipe, &pty.out_pipe_pty, null, 0) == windows.FALSE) {
+ return windows.unexpectedError(windows.GetLastError());
}
errdefer {
- _ = windows.CloseHandle(pty.out_pipe);
- _ = windows.CloseHandle(pty.out_pipe_pty);
+ _ = windows.exp.kernel32.CloseHandle(pty.out_pipe);
+ _ = windows.exp.kernel32.CloseHandle(pty.out_pipe_pty);
}
- try windows.SetHandleInformation(pty.in_pipe, windows.HANDLE_FLAG_INHERIT, 0);
- try windows.SetHandleInformation(pty.in_pipe_pty, windows.HANDLE_FLAG_INHERIT, 0);
- try windows.SetHandleInformation(pty.out_pipe, windows.HANDLE_FLAG_INHERIT, 0);
- try windows.SetHandleInformation(pty.out_pipe_pty, windows.HANDLE_FLAG_INHERIT, 0);
+ const SetHandleInformation = struct {
+ fn f(hObject: windows.HANDLE) !void {
+ if (windows.exp.kernel32.SetHandleInformation(
+ hObject,
+ windows.HANDLE_FLAG_INHERIT,
+ 0,
+ ) == windows.FALSE) {
+ return windows.unexpectedError(windows.GetLastError());
+ }
+ }
+ };
+
+ try SetHandleInformation.f(pty.in_pipe);
+ try SetHandleInformation.f(pty.in_pipe_pty);
+ try SetHandleInformation.f(pty.out_pipe);
+ try SetHandleInformation.f(pty.out_pipe_pty);
const result = windows.exp.kernel32.CreatePseudoConsole(
.{ .X = @intCast(size.ws_col), .Y = @intCast(size.ws_row) },
@@ -441,10 +454,10 @@ const WindowsPty = struct {
}
pub fn deinit(self: *Pty) void {
- _ = windows.CloseHandle(self.in_pipe_pty);
- _ = windows.CloseHandle(self.in_pipe);
- _ = windows.CloseHandle(self.out_pipe_pty);
- _ = windows.CloseHandle(self.out_pipe);
+ _ = windows.exp.kernel32.CloseHandle(self.in_pipe_pty);
+ _ = windows.exp.kernel32.CloseHandle(self.in_pipe);
+ _ = windows.exp.kernel32.CloseHandle(self.out_pipe_pty);
+ _ = windows.exp.kernel32.CloseHandle(self.out_pipe);
_ = windows.exp.kernel32.ClosePseudoConsole(self.pseudo_console);
self.* = undefined;
}