Fix #2913
This commit is contained in:
parent
4b0724530e
commit
df0c5d99e6
@ -54,18 +54,24 @@ In C:
|
|||||||
|
|
||||||
.. code-block:: c
|
.. code-block:: c
|
||||||
|
|
||||||
struct ttysize ts;
|
#include <stdio.h>
|
||||||
ioctl(0, TIOCGWINSZ, &ts);
|
#include <sys/ioctl.h>
|
||||||
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);
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
struct winsize sz;
|
||||||
|
ioctl(0, TIOCGWINSZ, &sz);
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
In Python:
|
In Python:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import array, fcntl, termios
|
import array, fcntl, sys, termios
|
||||||
buf = array.array('H', [0, 0, 0, 0])
|
buf = array.array('H', [0, 0, 0, 0])
|
||||||
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
|
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
|
||||||
print('number of columns: {}, number of rows: {}, screen width: {}, screen height: {}'.format(*buf))
|
print('number of rows: {}, number of columns: {}, screen width: {}, screen height: {}'.format(*buf))
|
||||||
|
|
||||||
Note that some terminals return ``0`` for the width and height values. Such
|
Note that some terminals return ``0`` for the width and height values. Such
|
||||||
terminals should be modified to return the correct values. Examples of
|
terminals should be modified to return the correct values. Examples of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user