From 029500f3ed54d613ed5bed00bb086cb1cf0896c0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 May 2018 18:27:18 +0530 Subject: [PATCH] Store fd for screen_size at creation time --- kitty/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kitty/utils.py b/kitty/utils.py index bd69b808e..329293410 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -78,7 +78,7 @@ def parse_color_set(raw): continue -def screen_size_function(): +def screen_size_function(fd=None): ans = getattr(screen_size_function, 'ans', None) if ans is None: from collections import namedtuple @@ -86,11 +86,13 @@ def screen_size_function(): import fcntl import termios Size = namedtuple('Size', 'rows cols width height cell_width cell_height') + if fd is None: + fd = sys.stdout def screen_size(): if screen_size.changed: buf = array.array('H', [0, 0, 0, 0]) - fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf) + fcntl.ioctl(fd, termios.TIOCGWINSZ, buf) rows, cols, width, height = tuple(buf) cell_width, cell_height = width // (cols or 1), height // (rows or 1) screen_size.ans = Size(rows, cols, width, height, cell_width, cell_height)