Skip to content

Commit 919f6ff

Browse files
committed
Call ioctl more defensively
1 parent c52b17b commit 919f6ff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

matplotlib-backend-kitty/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import termios
1111
import tty
1212
from base64 import standard_b64encode
13+
from contextlib import suppress
1314
from subprocess import run
1415

1516
from matplotlib import interactive, is_interactive
@@ -23,10 +24,14 @@
2324
interactive(True)
2425

2526
def term_size_px():
27+
width_px = height_px = 0
28+
2629
# try to get terminal size from ioctl
27-
buf = array.array("H", [0, 0, 0, 0])
28-
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
29-
_, _, width_px, height_px = buf
30+
with suppress(OSError):
31+
buf = array.array('H', [0, 0, 0, 0])
32+
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, buf)
33+
_, _, width_px, height_px = buf
34+
3035
if width_px != 0 and height_px != 0:
3136
return height_px, width_px
3237

0 commit comments

Comments
 (0)