Use tabs for C/Python code samples

This commit is contained in:
Kovid Goyal 2021-07-18 13:43:26 +05:30
parent f787a377c3
commit 380c7628d8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -51,28 +51,33 @@ client must be able to get the window size in pixels and the number of cells
per row and column. This can be done by using the ``TIOCGWINSZ`` ioctl. Some per row and column. This can be done by using the ``TIOCGWINSZ`` ioctl. Some
code to demonstrate its use code to demonstrate its use
In C: .. tab:: C
.. code-block:: c .. code-block:: c
#include <stdio.h> #include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
struct winsize sz; struct winsize sz;
ioctl(0, TIOCGWINSZ, &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); printf(
return 0; "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:
.. code-block:: python .. tab:: Python
import array, fcntl, sys, termios .. code-block:: python
buf = array.array('H', [0, 0, 0, 0])
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf) import array, fcntl, sys, termios
print('number of rows: {}, number of columns: {}, screen width: {}, screen height: {}'.format(*buf)) buf = array.array('H', [0, 0, 0, 0])
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, 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