mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
core: fix up pty Zig error sets
This commit is contained in:
66
src/pty.zig
66
src/pty.zig
@ -41,14 +41,16 @@ pub const Mode = packed struct {
|
|||||||
// a termio that doesn't use a pty. This isn't used in any user-facing
|
// a termio that doesn't use a pty. This isn't used in any user-facing
|
||||||
// artifacts, this is just a stopgap to get compilation to work on iOS.
|
// artifacts, this is just a stopgap to get compilation to work on iOS.
|
||||||
const NullPty = struct {
|
const NullPty = struct {
|
||||||
pub const Errors = error{GetModeFailed};
|
pub const Error = OpenError || GetModeError || SetSizeError || ChildPreExecError;
|
||||||
|
|
||||||
pub const Fd = posix.fd_t;
|
pub const Fd = posix.fd_t;
|
||||||
|
|
||||||
master: Fd,
|
master: Fd,
|
||||||
slave: Fd,
|
slave: Fd,
|
||||||
|
|
||||||
pub fn open(size: winsize) error{}!Pty {
|
pub const OpenError = error{};
|
||||||
|
|
||||||
|
pub fn open(size: winsize) OpenError!Pty {
|
||||||
_ = size;
|
_ = size;
|
||||||
return .{ .master = 0, .slave = 0 };
|
return .{ .master = 0, .slave = 0 };
|
||||||
}
|
}
|
||||||
@ -57,17 +59,23 @@ const NullPty = struct {
|
|||||||
_ = self;
|
_ = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getMode(self: Pty) error{GetModeFailed}!Mode {
|
pub const GetModeError = error{GetModeFailed};
|
||||||
|
|
||||||
|
pub fn getMode(self: Pty) GetModeError!Mode {
|
||||||
_ = self;
|
_ = self;
|
||||||
return .{};
|
return .{};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setSize(self: *Pty, size: winsize) error{}!void {
|
pub const SetSizeError = error{};
|
||||||
|
|
||||||
|
pub fn setSize(self: *Pty, size: winsize) SetSizeError!void {
|
||||||
_ = self;
|
_ = self;
|
||||||
_ = size;
|
_ = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn childPreExec(self: Pty) error{}!void {
|
pub const ChildPreExecError = error{};
|
||||||
|
|
||||||
|
pub fn childPreExec(self: Pty) ChildPreExecError!void {
|
||||||
_ = self;
|
_ = self;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -76,14 +84,7 @@ const NullPty = struct {
|
|||||||
/// of Linux syscalls. The caller is responsible for detail-oriented handling
|
/// of Linux syscalls. The caller is responsible for detail-oriented handling
|
||||||
/// of the returned file handles.
|
/// of the returned file handles.
|
||||||
const PosixPty = struct {
|
const PosixPty = struct {
|
||||||
pub const Errors = error{
|
pub const Error = OpenError || GetModeError || GetSizeError || SetSizeError || ChildPreExecError;
|
||||||
GetModeFailed,
|
|
||||||
IoctlFailed,
|
|
||||||
OpenPtyFailed,
|
|
||||||
OperationNotSupported,
|
|
||||||
ProcessGroupFailed,
|
|
||||||
SetControllingTerminalFailed,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Fd = posix.fd_t;
|
pub const Fd = posix.fd_t;
|
||||||
|
|
||||||
@ -111,10 +112,10 @@ const PosixPty = struct {
|
|||||||
master: Fd,
|
master: Fd,
|
||||||
slave: Fd,
|
slave: Fd,
|
||||||
|
|
||||||
|
pub const OpenError = error{OpenptyFailed};
|
||||||
|
|
||||||
/// Open a new PTY with the given initial size.
|
/// Open a new PTY with the given initial size.
|
||||||
pub fn open(size: winsize) error{
|
pub fn open(size: winsize) OpenError!Pty {
|
||||||
OpenptyFailed,
|
|
||||||
}!Pty {
|
|
||||||
// Need to copy so that it becomes non-const.
|
// Need to copy so that it becomes non-const.
|
||||||
var sizeCopy = size;
|
var sizeCopy = size;
|
||||||
|
|
||||||
@ -171,7 +172,9 @@ const PosixPty = struct {
|
|||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getMode(self: Pty) error{GetModeFailed}!Mode {
|
pub const GetModeError = error{GetModeFailed};
|
||||||
|
|
||||||
|
pub fn getMode(self: Pty) GetModeError!Mode {
|
||||||
var attrs: c.termios = undefined;
|
var attrs: c.termios = undefined;
|
||||||
if (c.tcgetattr(self.master, &attrs) != 0)
|
if (c.tcgetattr(self.master, &attrs) != 0)
|
||||||
return error.GetModeFailed;
|
return error.GetModeFailed;
|
||||||
@ -182,8 +185,10 @@ const PosixPty = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const GetSizeError = error{IoctlFailed};
|
||||||
|
|
||||||
/// Return the size of the pty.
|
/// Return the size of the pty.
|
||||||
pub fn getSize(self: Pty) error{IoctlFailed}!winsize {
|
pub fn getSize(self: Pty) GetSizeError!winsize {
|
||||||
var ws: winsize = undefined;
|
var ws: winsize = undefined;
|
||||||
if (c.ioctl(self.master, TIOCGWINSZ, @intFromPtr(&ws)) < 0)
|
if (c.ioctl(self.master, TIOCGWINSZ, @intFromPtr(&ws)) < 0)
|
||||||
return error.IoctlFailed;
|
return error.IoctlFailed;
|
||||||
@ -191,15 +196,19 @@ const PosixPty = struct {
|
|||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const SetSizeError = error{IoctlFailed};
|
||||||
|
|
||||||
/// Set the size of the pty.
|
/// Set the size of the pty.
|
||||||
pub fn setSize(self: *Pty, size: winsize) error{IoctlFailed}!void {
|
pub fn setSize(self: *Pty, size: winsize) SetSizeError!void {
|
||||||
if (c.ioctl(self.master, TIOCSWINSZ, @intFromPtr(&size)) < 0)
|
if (c.ioctl(self.master, TIOCSWINSZ, @intFromPtr(&size)) < 0)
|
||||||
return error.IoctlFailed;
|
return error.IoctlFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const ChildPreExecError = error{ OperationNotSupported, ProcessGroupFailed, SetControllingTerminalFailed };
|
||||||
|
|
||||||
/// This should be called prior to exec in the forked child process
|
/// This should be called prior to exec in the forked child process
|
||||||
/// in order to setup the tty properly.
|
/// in order to setup the tty properly.
|
||||||
pub fn childPreExec(self: Pty) error{ OperationNotSupported, ProcessGroupFailed, SetControllingTerminalFailed }!void {
|
pub fn childPreExec(self: Pty) ChildPreExecError!void {
|
||||||
// Reset our signals
|
// Reset our signals
|
||||||
var sa: posix.Sigaction = .{
|
var sa: posix.Sigaction = .{
|
||||||
.handler = .{ .handler = posix.SIG.DFL },
|
.handler = .{ .handler = posix.SIG.DFL },
|
||||||
@ -240,10 +249,7 @@ const PosixPty = struct {
|
|||||||
|
|
||||||
/// Windows PTY creation and management.
|
/// Windows PTY creation and management.
|
||||||
const WindowsPty = struct {
|
const WindowsPty = struct {
|
||||||
pub const Errors = error{
|
pub const Error = OpenError || GetSizeError || SetSizeError;
|
||||||
ResizeFailed,
|
|
||||||
Unexpected,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Fd = windows.HANDLE;
|
pub const Fd = windows.HANDLE;
|
||||||
|
|
||||||
@ -257,8 +263,10 @@ const WindowsPty = struct {
|
|||||||
pseudo_console: windows.exp.HPCON,
|
pseudo_console: windows.exp.HPCON,
|
||||||
size: winsize,
|
size: winsize,
|
||||||
|
|
||||||
|
pub const OpenError = error{Unexpected};
|
||||||
|
|
||||||
/// Open a new PTY with the given initial size.
|
/// Open a new PTY with the given initial size.
|
||||||
pub fn open(size: winsize) error{Unexpected}!Pty {
|
pub fn open(size: winsize) OpenError!Pty {
|
||||||
var pty: Pty = undefined;
|
var pty: Pty = undefined;
|
||||||
|
|
||||||
var pipe_path_buf: [128]u8 = undefined;
|
var pipe_path_buf: [128]u8 = undefined;
|
||||||
@ -367,13 +375,17 @@ const WindowsPty = struct {
|
|||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const GetSizeError = error{};
|
||||||
|
|
||||||
/// Return the size of the pty.
|
/// Return the size of the pty.
|
||||||
pub fn getSize(self: Pty) error{}!winsize {
|
pub fn getSize(self: Pty) GetSizeError!winsize {
|
||||||
return self.size;
|
return self.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const SetSizeError = error{ResizeFailed};
|
||||||
|
|
||||||
/// Set the size of the pty.
|
/// Set the size of the pty.
|
||||||
pub fn setSize(self: *Pty, size: winsize) error{ResizeFailed}!void {
|
pub fn setSize(self: *Pty, size: winsize) SetSizeError!void {
|
||||||
const result = windows.exp.kernel32.ResizePseudoConsole(
|
const result = windows.exp.kernel32.ResizePseudoConsole(
|
||||||
self.pseudo_console,
|
self.pseudo_console,
|
||||||
.{ .X = @intCast(size.ws_col), .Y = @intCast(size.ws_row) },
|
.{ .X = @intCast(size.ws_col), .Y = @intCast(size.ws_row) },
|
||||||
|
Reference in New Issue
Block a user