#Terminal dimensions (width and height)
1 messages · Page 1 of 1 (latest)
Hey! I’m away from my computer so I can’t give super detailed instructions. I’ve done this before though. Try looking at my term.zig file for my fuzzy finder. https://github.com/natecraddock/zf/blob/master/src/term.zig. The important parts are opening the /dev/tty file and the windowSize function.
Which OS
Does this work on windows?
Ah, read it, no, it would not, ok ok
I am on windows
Oki, This is a side I have touched a little
first
You will have to use at the bare minimum windows libs
since those are the ones that defines that
So you have to link kernel32 at the bare minimum
Now "link" I say, but really is just getting the functions you will use
https://learn.microsoft.com/en-us/windows/console/console-functions - This are your available Console functions
now they are in C as you can see
There are a few functions under std.os.windows.kernel32 too
But you said no libs, so I guess std counts @bleak sable ?
to get a external function (For example AllocConsole) we have:
extern "kernel32" fn AllocConsole() void;
std is fine, just dont want to mush bloat. Just to keep simple (if that makes sens)
Thanks for the help. I will have a look. I am new to low level programming so it is a lot to take in.
pub fn wWinMain(hInstance: std.os.windows.HINSTANCE, hPrevInstance: std.os.windows.HINSTANCE, lpCmdLine: std.os.windows.LPWSTR, nCmdShow: c_int) c_int {
_ = hInstance;
_ = hPrevInstance;
_ = lpCmdLine;
_ = nCmdShow;
var info : std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
var current_terminal_handler = std.os.windows.kernel32.GetStdHandle(std.os.windows.STD_OUTPUT_HANDLE) orelse return 2;
if(
std.os.windows.kernel32.GetConsoleScreenBufferInfo(current_terminal_handler, &info) == 0
) {
return 1;
}
std.log.err("size is x = {}, y = {}", .{info.dwSize.X, info.dwSize.Y});
std.log.err("cursor is x = {}, y = {}", .{info.dwCursorPosition.X, info.dwCursorPosition.Y});
std.log.err("attributes is {}", .{info.wAttributes});
return 0;
}
Not on windows can't test
i mean
wine ig+
Something along those lines
doesnt compile but I think understand your code
const std = @import("std");
pub fn wWinMain(hInstance: ?std.os.windows.HINSTANCE, hPrevInstance: ?std.os.windows.HINSTANCE, lpCmdLine: std.os.windows.LPWSTR, nCmdShow: c_int) c_int {
_ = hInstance;
_ = hPrevInstance;
_ = lpCmdLine;
_ = nCmdShow;
var info : std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
var current_terminal_handler = std.os.windows.kernel32.GetStdHandle(std.os.windows.STD_OUTPUT_HANDLE) orelse return 2;
if(
std.os.windows.kernel32.GetConsoleScreenBufferInfo(current_terminal_handler, &info) == 0
) {
return 1;
}
std.log.err("size is x = {}, y = {}", .{info.dwSize.X, info.dwSize.Y});
std.log.err("cursor is x = {}, y = {}", .{info.dwCursorPosition.X, info.dwCursorPosition.Y});
std.log.err("attributes is {}", .{info.wAttributes});
return 0;
}
corrected
Thanks a lot ❤️
Is wWinMain the entry point?
on windows
yes
You can use wWinMain and main