]> gitweb.ps.run Git - iftint/blob - termsize.c
object editing, press space to edit existing primitive node
[iftint] / termsize.c
1 #ifdef _WIN32
2
3 #include <stdio.h>
4 #include <windows.h>
5
6 int main(int argc, char *argv[]) 
7 {
8     CONSOLE_SCREEN_BUFFER_INFO csbi;
9     int columns, rows;
10   
11     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
12     columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
13     rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
14   
15     printf("columns: %d\n", columns);
16     printf("rows: %d\n", rows);
17     return 0;
18 }
19
20 #else
21
22 #include <stdio.h>
23 #include <sys/ioctl.h>
24 #include <unistd.h>
25
26 int main (int argc, char **argv)
27 {
28     struct winsize w;
29     ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
30
31     printf ("lines %d\n", w.ws_row);
32     printf ("columns %d\n", w.ws_col);
33     return 0;  // make sure your main returns int
34 }
35
36 #endif
37