mirror of
https://github.com/Tilo-K/csvu.git
synced 2026-01-10 08:31:01 +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;
|
const os_tag = builtin.os.tag;
|
||||||
|
|
||||||
switch (os_tag) {
|
switch (os_tag) {
|
||||||
.linux, .macos, .freebsd, .openbsd, .netbsd => {
|
.linux, .freebsd, .openbsd, .netbsd => {
|
||||||
return try getUnixTerminalDimensions();
|
return try getUnixTerminalDimensions();
|
||||||
},
|
},
|
||||||
.windows => {
|
.windows => {
|
||||||
return try getWindowsTerminalDimensions();
|
return try getWindowsTerminalDimensions();
|
||||||
},
|
},
|
||||||
|
.macos => {
|
||||||
|
return try getMacOsTerminalDimensions();
|
||||||
|
},
|
||||||
else => {
|
else => {
|
||||||
return Error.UnsupportedOs;
|
return Error.UnsupportedOs;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +35,18 @@ fn getUnixTerminalDimensions() !Dimensions {
|
|||||||
return Dimensions{ .width = size.ws_col, .height = size.ws_row };
|
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 {
|
fn getWindowsTerminalDimensions() !Dimensions {
|
||||||
const win = std.os.windows;
|
const win = std.os.windows;
|
||||||
const handle = win.GetStdHandle(win.STD_OUTPUT_HANDLE) catch return Error.ErrorFetchingDimensions;
|
const handle = win.GetStdHandle(win.STD_OUTPUT_HANDLE) catch return Error.ErrorFetchingDimensions;
|
||||||
|
|||||||
Reference in New Issue
Block a user