#Get amount of rows and columns in console.

1 messages · Page 1 of 1 (latest)

weak plinth
#

Just had a question, how do I get the amount of rows and columns in the console window that the program is being run in?

#

I guess whatever the equivalent

#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>

int main (int argc, char **argv)
{
    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);

    printf ("lines %d\n", w.ws_row);
    printf ("columns %d\n", w.ws_col);
    return 0;  // make sure your main returns int
}

of this

green temple
#
const std = @import("std");
const linux = std.os.linux;

pub fn main() void {
    var w: linux.winsize = undefined;
    _ = linux.ioctl(linux.STDOUT_FILENO, linux.T.IOCGWINSZ, @intFromPtr(&w));

    std.debug.print(
        \\lines {d}
        \\columns {d}
        \\
    , .{ w.ws_row, w.ws_col });
}
weak plinth
#

oh, i see