#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
int main( int argc, char **argv ){
struct winsize size;
ioctl( 0, TIOCSWINSZ, (char *) &size );
printf( "Rows: %u\nCols: %u\n", size.ws_row, size.ws_col );
return 0;
}
I was using Vim to code this program, and I had Vim suspended when I compiled it. When I ran it, I got ridiculously high values (in the thousands) for both terminal dimensions, and when I started Vim again, there was a massive overload of.. something. I don't know what happened, but my terminal window was all static, and the Activity Monitor showed the memory usage of Vim as 1 GB and climbing. I had to force quit the Terminal.
How can I do this without causing a memory overload (or whatever it was)? I don't really care that much about ioctl(), mostly I just want to know how to get the correct terminal dimensions.


Sign In
Create Account


Back to top









