From 380c7628d89f10f38e9c22fb5b827e107e612ceb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Jul 2021 13:43:26 +0530 Subject: [PATCH] Use tabs for C/Python code samples --- docs/graphics-protocol.rst | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/graphics-protocol.rst b/docs/graphics-protocol.rst index 211d21d55..d183ded9b 100644 --- a/docs/graphics-protocol.rst +++ b/docs/graphics-protocol.rst @@ -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 code to demonstrate its use -In C: +.. tab:: C -.. code-block:: c + .. code-block:: c - #include - #include + #include + #include - 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; - } + 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: -.. code-block:: python +.. tab:: Python - import array, fcntl, sys, termios - 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)) + .. code-block:: python + + import array, fcntl, sys, termios + 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 terminals should be modified to return the correct values. Examples of