From 44866a6e79ae5562b392a4c36d53c407ac396bc0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 7 Jan 2023 15:00:51 +0530 Subject: [PATCH] Add sample Go code to get screen size --- docs/graphics-protocol.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/graphics-protocol.rst b/docs/graphics-protocol.rst index 3754a876d..19858ba4e 100644 --- a/docs/graphics-protocol.rst +++ b/docs/graphics-protocol.rst @@ -88,6 +88,17 @@ code to demonstrate its use 'number of rows: {} number of columns: {}' 'screen width: {} screen height: {}').format(*buf)) +.. tab:: Go + + .. code-block:: go + + import "golang.org/x/sys/unix" + fd, err := unix.Open(fd, unix.O_NOCTTY|unix.O_CLOEXEC|unix.O_NDELAY|unix.O_RDWR, 0666) + sz, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ) + fmt.Println("rows: %v columns: %v width: %v height %v", sz.Row, sz.Col, sz.Xpixel, sz.Ypixel) + + + 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 that return correct values: ``kitty, xterm``