mirror of
https://github.com/Tilo-K/csvu.git
synced 2026-01-09 00:01:00 +00:00
feat: fix macos support
This commit is contained in:
19
src/term.zig
19
src/term.zig
@@ -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