Skip to content

Commit df0c5d9

Browse files
committed
Fix #2913
1 parent 4b07245 commit df0c5d9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/graphics-protocol.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7177
terminals should be modified to return the correct values. Examples of

0 commit comments

Comments
 (0)