From df0c5d99e6cb8c60edb9312d0fa9dc53e3aaea3a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 11 Aug 2020 20:13:50 +0530 Subject: [PATCH] Fix #2913 --- docs/graphics-protocol.rst | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/graphics-protocol.rst b/docs/graphics-protocol.rst index 95893779b..6a5062cb9 100644 --- a/docs/graphics-protocol.rst +++ b/docs/graphics-protocol.rst @@ -54,18 +54,24 @@ In C: .. code-block:: c - struct ttysize ts; - ioctl(0, TIOCGWINSZ, &ts); - 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); + #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; + } In Python: .. code-block:: python - import array, fcntl, termios + import array, fcntl, sys, termios buf = array.array('H', [0, 0, 0, 0]) 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 terminals should be modified to return the correct values. Examples of