@@ -54,18 +54,24 @@ In C:
5454
5555.. code-block :: c
5656
57- struct ttysize ts;
58- ioctl(0, TIOCGWINSZ, &ts);
59- printf("number of columns: %i, number of rows: %i, screen width: %i, screen height: %i\n", sz.ws_col, sz.ws_row, sz.ws_xpixel, sz.ws_ypixel);
57+ #include <stdio.h>
58+ #include <sys/ioctl.h>
59+
60+ int main(int argc, char **argv) {
61+ struct winsize sz;
62+ ioctl(0, TIOCGWINSZ, &sz);
63+ printf("number of rows: %i, number of columns: %i, screen width: %i, screen height: %i\n", sz.ws_row, sz.ws_col, sz.ws_xpixel, sz.ws_ypixel);
64+ return 0;
65+ }
6066
6167 In Python:
6268
6369.. code-block :: python
6470
65- import array, fcntl, termios
71+ import array, fcntl, sys, termios
6672 buf = array.array(' H' , [0 , 0 , 0 , 0 ])
6773 fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ , buf)
68- print (' number of columns : {} , number of rows : {} , screen width: {} , screen height: {} ' .format(* buf))
74+ print (' number of rows : {} , number of columns : {} , screen width: {} , screen height: {} ' .format(* buf))
6975
7076 Note that some terminals return ``0 `` for the width and height values. Such
7177terminals should be modified to return the correct values. Examples of
0 commit comments