feat: fix macos support
This commit is contained in:
1 parent
cf17c6354f
commit
12fe0287da
2 files changed
+17
-2
No files matched your search
+17
-2
@@ -9,15 +9,18 @@ pub fn getTerminalDimensions() !Dimensions {
|
||||
const os_tag = builtin.os.tag;
|
||||
|
||||
switch (os_tag) {
|
||||
.linux, .macos, .freebsd, .openbsd, .netbsd => {
|
||||
.linux, .freebsd, .openbsd, .netbsd => {
|
||||
return try getUnixTerminalDimensions();
|
||||
},
|
||||
.windows => {
|
||||
return try getWindowsTerminalDimensions();
|
||||
},
|
||||
.macos => {
|
||||
return try getMacOsTerminalDimensions();
|
||||
},
|
||||
else => {
|
||||
return Error.UnsupportedOs;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +35,18 @@ fn getUnixTerminalDimensions() !Dimensions {
|
||||
return Dimensions{ .width = size.ws_col, .height = size.ws_row };
|
||||
}
|
||||
|
||||
pub fn getMacOsTerminalDimensions() !Dimensions {
|
||||
var ws: std.posix.winsize = undefined;
|
||||
const fd = std.io.getStdOut().handle;
|
||||
|
||||
_ = std.c.ioctl(fd, std.posix.T.IOCGWINSZ, @intFromPtr(&ws));
|
||||
|
||||
return Dimensions{
|
||||
.width = ws.col,
|
||||
.height = ws.row,
|
||||
};
|
||||
}
|
||||
|
||||
fn getWindowsTerminalDimensions() !Dimensions {
|
||||
const win = std.os.windows;
|
||||
const handle = win.GetStdHandle(win.STD_OUTPUT_HANDLE) catch return Error.ErrorFetchingDimensions;
|
||||
|
||||
Reference in new issue
Block a user